encrypt static method

Future<Payload> encrypt(
  1. Package package, {
  2. required SecretKey secretKey,
})

Implementation

static Future<Payload> encrypt(
  Package package, {
  required SecretKey secretKey,
}) async {
  final cipher = AesCtr.with256bits(
    macAlgorithm: Hmac.sha384(),
  );
  final preNonce = await cipher.newSecretKey();
  final nonce = await package.calculateNonce(preNonce: preNonce);
  final subkeys = await secretKey.deriveSubkeysV1(nonce: nonce);
  final secretBox = await cipher.encrypt(
    package.content,
    nonce: nonce.bytes.sublist(halfNonceLength, nonceLength),
    secretKey: subkeys.encryptionKey,
  );
  final mac = await calculateMac(
    Token.preAuthenticationEncoding(
      header: header,
      payload: PayloadLocal(
        secretBox: secretBox,
        nonce: nonce,
      ),
      footer: package.footer,
    ),
    subkeys: subkeys,
  );
  return PayloadLocal(
    nonce: nonce,
    secretBox: secretBox,
    mac: mac,
  );
}