@@ -15,6 +15,8 @@ library woosignal;
1515// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1616// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1717
18+ import 'dart:convert' ;
19+
1820import 'package:woosignal/models/response/api_data.dart' ;
1921import 'package:woosignal/models/response/continent.dart' ;
2022import 'package:woosignal/models/response/currencies.dart' ;
@@ -51,24 +53,37 @@ import 'package:woosignal/models/response/system_status.dart';
5153import 'package:woosignal/models/response/setting_option.dart' ;
5254import 'package:woosignal/models/response/setting_option_batch.dart' ;
5355import 'package:woosignal/models/response/product_batch.dart' ;
56+ import 'package:encrypt/encrypt.dart' as enc;
57+ import 'package:encrypt/encrypt.dart' ;
5458
5559/// WooSignal Package version
56- const String wooSignalVersion = "3.7.1 " ;
60+ const String wooSignalVersion = "3.8.0 " ;
5761
5862class WooSignal {
5963 WooSignal ._privateConstructor ();
6064 static final WooSignal instance = WooSignal ._privateConstructor ();
6165
6266 late ApiProvider _apiProvider;
6367 bool ? _debugMode;
68+ String ? _encryptKey, _encryptSecret;
6469
6570 /// Initialize the class
66- Future <void > init ({required String ? appKey, bool debugMode = false }) async {
71+ Future <void > init (
72+ {required String ? appKey,
73+ bool debugMode = false ,
74+ String ? encryptKey,
75+ String ? encryptSecret}) async {
6776 assert (appKey != null && appKey != "" ,
6877 "Provide a valid app key. Visit https://woosignal.com" );
6978 _apiProvider = ApiProvider (
7079 appKey: appKey! , debugMode: debugMode, version: wooSignalVersion);
7180 setDebugMode (debugMode);
81+ if (encryptKey != null ) {
82+ _encryptKey = encryptKey;
83+ }
84+ if (encryptSecret != null ) {
85+ _encryptSecret = encryptSecret;
86+ }
7287 await _apiProvider.init ();
7388 }
7489
@@ -121,14 +136,45 @@ class WooSignal {
121136 return model;
122137 }
123138
139+ String encrypt (String text) {
140+ if (_encryptKey == null ) {
141+ return "" ;
142+ }
143+ if (_encryptSecret == null ) {
144+ return "" ;
145+ }
146+ final key = enc.Key .fromUtf8 (_encryptKey! );
147+ final iv = IV .fromUtf8 (_encryptSecret! );
148+ final encrypter = Encrypter (AES (key, mode: AESMode .cbc));
149+ final encrypted = encrypter.encrypt (text, iv: iv);
150+ return encrypted.base64;
151+ }
152+
153+ String decrypt (String text) {
154+ if (_encryptKey == null ) {
155+ return "" ;
156+ }
157+ if (_encryptSecret == null ) {
158+ return "" ;
159+ }
160+ final key = enc.Key .fromUtf8 (_encryptKey! );
161+ final iv = IV .fromUtf8 (_encryptSecret! );
162+ final encrypter = Encrypter (AES (key, mode: AESMode .cbc));
163+ final decrypted = encrypter.decrypt (Encrypted .fromBase64 (text), iv: iv);
164+ return decrypted;
165+ }
166+
124167 /// Get app information from WooSignal
125- Future <WooSignalApp ?> getApp () async {
126- dynamic response = await _apiProvider.get ("/app" );
168+ Future <WooSignalApp ?> getApp ({bool encrypted = false }) async {
169+ dynamic response =
170+ await _apiProvider.get ("/app" , data: {"encrypted" : encrypted});
127171 if (response == null ) {
128172 return null ;
129173 }
174+ if (encrypted == true ) {
175+ response = jsonDecode (decrypt (response));
176+ }
130177 WooSignalApp wooSignalApp = WooSignalApp .fromJson (response);
131-
132178 _printLog (wooSignalApp.toString ());
133179 return wooSignalApp;
134180 }
0 commit comments