Trying to use this package in Flutter Flow, but I get an ArgumentError when the secret key is invalid. The code is below.
Future<String?> decryptString(String ciphertext, String secretKeyB64) async {
if (ciphertext.split(';').length != 3) {
return null;
}
final secretKey = SecretKey(convert.Base64Decoder().convert(secretKeyB64));
final algo = Chacha20(macAlgorithm: Hmac.sha256());
var [nonceStr, ctStr, macStr] = ciphertext.split(';');
final nonce = convert.Base64Decoder().convert(nonceStr);
final ct = convert.Base64Decoder().convert(ctStr);
final mac = convert.Base64Decoder().convert(macStr);
final box = SecretBox(ct, nonce: nonce, mac: Mac(mac));
try {
await box
.checkMac(macAlgorithm: Hmac.sha256(), secretKey: secretKey, aad: []);
} on Exception {
return null;
} on ArgumentError {
return null;
}
final pt = await algo.decrypt(box, secretKey: secretKey);
return convert.Utf8Decoder().convert(pt);
}
When I run similar code from the console and supply the wrong key, it instead throws an authentication error.
Not sure if there is a versioning issue with the dependencies or just a platform difference, but it does not make sense to require an argument and then not support it.
Trying to use this package in Flutter Flow, but I get an ArgumentError when the secret key is invalid. The code is below.
When I run similar code from the console and supply the wrong key, it instead throws an authentication error.
Not sure if there is a versioning issue with the dependencies or just a platform difference, but it does not make sense to require an argument and then not support it.