decrypt static method
Decrypts a value with a password using AES/CBC/PKCS7 KDF is Sha256KDF if not specified
Implementation
static Uint8List decrypt(dynamic value, String password, {KDF? kdf}) {
kdf = kdf ?? Sha256KDF();
Uint8List valBytes;
if (value is String) {
valBytes = NanoHelpers.hexToBytes(value);
} else if (value is Uint8List) {
valBytes = value;
} else {
throw Exception('Value should be a string or a byte array');
}
Uint8List salt = valBytes.sublist(8, 16);
KeyIV key = kdf.deriveKey(password, salt: salt);
// Decrypt
Uint8List encData = valBytes.sublist(16);
return AesCbcPkcs7.decrypt(encData, key: key.key, iv: key.iv);
}