Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument Error: aad not supported, but it is a required argument #157

Open
k98kurz opened this issue Aug 23, 2023 · 0 comments
Open

Argument Error: aad not supported, but it is a required argument #157

k98kurz opened this issue Aug 23, 2023 · 0 comments

Comments

@k98kurz
Copy link

k98kurz commented Aug 23, 2023

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.

@k98kurz k98kurz changed the title Argument Error: add not supported, but it is a required argument Argument Error: aad not supported, but it is a required argument Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant