25-1/28/1

This commit is contained in:
Hamza-Ayed
2025-01-28 01:03:39 +03:00
parent 63681f104c
commit f217b5a34f
102 changed files with 7253 additions and 3945 deletions

View File

@@ -0,0 +1,52 @@
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/foundation.dart';
import '../../env/env.dart';
var secretKey = Env.keyOfApp
.toString()
.split('XrXlBl')[0]; // Must be 16 characters for AES-128
String initializationVector = Env.initializationVector; // Must be 16 characters
final encryptionHelper = EncryptionHelper(
secretKey: secretKey,
initializationVector: initializationVector,
);
class EncryptionHelper {
final encrypt.Key key;
final encrypt.IV iv;
EncryptionHelper(
{required String secretKey, required String initializationVector})
: key = encrypt.Key.fromUtf8(secretKey),
iv = encrypt.IV.fromUtf8(initializationVector);
// Initialize the helper
/// Encrypts the given plain text
String encryptData(String plainText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypted = encrypter.encrypt(plainText, iv: iv);
return encrypted.base64;
} catch (e) {
debugPrint('Encryption Error: $e');
return '';
}
}
/// Decrypts the given encrypted text
String decryptData(String encryptedText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypted = encrypt.Encrypted.fromBase64(encryptedText);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
return decrypted;
} catch (e) {
debugPrint('Decryption Error: $e');
return '';
}
}
}