decrypt static method
Implementation
static Future<Package> decrypt(
Token token, {
required SecretKey secretKey,
}) async {
final payload = token.payloadLocal;
if (payload == null) throw UnsupportedError('Invalid payload type.');
final secretBox = payload.secretBox;
final nonce = payload.nonce;
if (nonce == null) {
throw Exception('Missing nonce');
}
if (secretBox == null) {
throw Exception('Missing secretBox');
}
final cipher = Xchacha20.poly1305Aead();
final content = await cipher.decrypt(
SecretBox(
secretBox.cipherText,
nonce: nonce.bytes,
mac: Mac.empty,
),
aad: token.localAADPreAuthenticationEncoding,
secretKey: secretKey,
);
return Package(
content: content.sublist(0, secretBox.cipherText.length - 16),
footer: token.footer,
);
}