You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
decrypted return SecretBox has wrong message authentication code (MAC) #71
I received from python the Ciphertext (this is formated from StringEcrypted + first 4 elements from MAC.
When I'll try to decrypt the message I received wrong MAC.
I think the problem is on MAC. I'm able to set the MAC length with 4 on the SecretBox?
I'll add the code:
Future<List> decrypt(List message) async {
final algorithm = AesGcm.with128bits();
final key = await kdf(isEncrypt: true);
final secretKey = SecretKey(key);
final mac = Mac(message.skip(message.length - 4).toList());
final secretMessage =
SecretBox(message.take(message.length - 4).toList(), nonce: HEX.decode(cpIV), mac: mac);
final clearText = await algorithm.decrypt(secretMessage, secretKey: secretKey);
print(clearText);
return clearText;
}
final streamCipherAlgorithm = crypto.Xchacha20.poly1305Aead();
final nonce = streamCipherAlgorithm.newNonce();
crypto.SecretKey secretKey = await streamCipherAlgorithm
.newSecretKeyFromBytes(argonResult.rawBytes);
crypto.SecretBox secretBox = await streamCipherAlgorithm.encrypt(
utf8.encode(initialMessage),
secretKey: secretKey,
nonce: nonce,
aad: utf8.encode(associatedData),
);
String encryptedInitialMessage = base64Encode(secretBox.cipherText); // encryptedInitialMessage is sent to the other party along with Mac and nonce.
Activity
ramvdixit commentedon Dec 13, 2022
This issue is still there. Here is my code:
Encryption
Decryption
Decryption fails with 'SecretBox has wrong Message Authentication Code (MAC)' error.
I have tried using the 'Cipher' class as shown in the example, still fails on decryption with the same exception.
terrier989 commentedon Mar 3, 2023
I believe any possible issue was fixed in cryptography 2.2.0 + cryptography_flutter 2.1.0.