aesDecrypt function
Implementation
String aesDecrypt({required String cipherText, required String secretKey}) {
try {
Uint8List encryptedBytesWithSalt = base64.decode(cipherText);
Uint8List encryptedBytes =
encryptedBytesWithSalt.sublist(16, encryptedBytesWithSalt.length);
final salt = encryptedBytesWithSalt.sublist(8, 16);
var keyndIV = deriveKeyAndIV(secretKey, salt);
final key = encrypt.Key(keyndIV.first);
final iv = encrypt.IV(keyndIV.last);
final encrypter = encrypt.Encrypter(
encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7"));
final decrypted =
encrypter.decrypt64(base64.encode(encryptedBytes), iv: iv);
return decrypted;
} catch (error) {
log('decryptAESCryptoJS:error $error');
rethrow;
}
}