decrypt static method
Decrypts the given data using AES encryption with the provided keyString.
The keyString must be 32 characters long. The optional ivString must be 32 characters long.
If ivString is not provided, a part of keyString will be used as the initialization vector (IV).
Returns the decrypted data as a string.
Throws an ArgumentError if keyString is not 32 characters long.
Implementation
static String decrypt(
String data,
String keyString, {
String? ivString,
encriptor.AESMode mode = encriptor.AESMode.sic,
}) {
if (data.isEmpty) {
return '';
} else if (keyString.length < 32) {
return 'keyString long must be 32 characters.';
}
final key = encriptor.Key.fromUtf8(keyString.substring(0, 32));
final iv = encriptor.IV.fromUtf8(ivString ?? keyString.substring(0, 16));
final encrypter = encriptor.Encrypter(encriptor.AES(key, mode: mode));
try {
return encrypter.decrypt64(data, iv: iv);
} catch (_) {
return '::: Error decrypting data';
}
}