service 2-5-26-1
This commit is contained in:
@@ -2,8 +2,10 @@ import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:service/env/env.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
import 'package:service/constant/char_map.dart';
|
||||
import 'package:service/print.dart';
|
||||
|
||||
|
||||
class EncryptionHelper {
|
||||
static EncryptionHelper? _instance;
|
||||
@@ -28,29 +30,35 @@ class EncryptionHelper {
|
||||
}
|
||||
debugPrint("Initializing EncryptionHelper...");
|
||||
// Read stored keys
|
||||
String? keyOfApp = Env.keyOfApp;
|
||||
// Log.print('keyOfApp: ${keyOfApp}');
|
||||
String? initializationVector = Env.initializationVector;
|
||||
// Log.print('initializationVector: ${initializationVector}');
|
||||
String keyOfApp = r(Env.keyOfApp).toString().split(Env.addd)[0];
|
||||
String initializationVector = r(Env.initializationVector).toString().split(Env.addd)[0];
|
||||
|
||||
Log.print('Key Length: ${keyOfApp.length}');
|
||||
Log.print('IV Length: ${initializationVector.length}');
|
||||
|
||||
// Set the global instance
|
||||
_instance = EncryptionHelper._(
|
||||
encrypt.Key.fromUtf8(keyOfApp!),
|
||||
encrypt.IV.fromUtf8(initializationVector!),
|
||||
encrypt.Key.fromUtf8(keyOfApp),
|
||||
encrypt.IV.fromUtf8(initializationVector),
|
||||
);
|
||||
debugPrint("EncryptionHelper initialized successfully.");
|
||||
}
|
||||
|
||||
|
||||
/// Encrypts a string
|
||||
String encryptData(String plainText) {
|
||||
Log.print('Encrypting: $plainText');
|
||||
try {
|
||||
|
||||
final encrypter =
|
||||
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
|
||||
final encrypted = encrypter.encrypt(plainText, iv: iv);
|
||||
return encrypted.base64;
|
||||
} catch (e) {
|
||||
debugPrint('Encryption Error: $e');
|
||||
Log.print('Encryption Error: $e');
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Decrypts a string
|
||||
@@ -66,3 +74,14 @@ class EncryptionHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r(String string) {
|
||||
var res = X.r(X.r(X.r(string, cn), cC), cs).toString();
|
||||
// Log.print('r($string) => $res');
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
c(String string) {
|
||||
return X.c(X.c(X.c(string, cn), cC), cs).toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user