decrypt function
Implementation
Future<String> decrypt({
required String symKey,
required String encoded,
}) async {
final decoded = deserialize(encoded);
try {
// final secretKey = crypto.SecretKey(hex.decode(symKey));
// final mac = await crypto.Chacha20.poly1305Aead()
// .macAlgorithm
// .calculateMac(decoded.sealed, secretKey: secretKey, nonce: decoded.iv);
// final message = await crypto.Chacha20.poly1305Aead().decrypt(
// crypto.SecretBox(decoded.sealed, nonce: decoded.iv, mac: mac),
// secretKey: secretKey,
// );
final box = AEADChaCha20Poly1305.withIV(
Uint8List.fromList(hex.decode(symKey)),
decoded.iv,
);
final message = box.decrypt(decoded.sealed);
return utf8.decode(message);
} catch (e) {
throw WCException("Failed to decrypt");
}
}