encrypt static method
Implementation
static Future<Payload> encrypt(
Package package, {
required SecretKey secretKey,
}) async {
final cipher = Xchacha20.poly1305Aead();
final preNonce = await cipher.newSecretKey();
final fullNonce = await package.calculateNonce(preNonce: preNonce);
final nonce = Mac(fullNonce.bytes.sublist(0, 24));
final secretBox = await cipher.encrypt(
package.content,
aad: Token.preAuthenticationEncoding(
header: header,
payload: PayloadLocal(
secretBox: null,
nonce: nonce,
),
footer: package.footer,
),
nonce: nonce.bytes,
secretKey: secretKey,
);
return PayloadLocal(
nonce: nonce,
secretBox: SecretBox(
secretBox.cipherText + secretBox.mac.bytes,
nonce: secretBox.nonce,
mac: secretBox.mac,
),
);
}