open static method

Future<Uint8List> open(
  1. Uint8List sealed,
  2. X25519KeyAgreement recipient
)

Opens a sealed box with the recipient's key agreement capability.

Implementation

static Future<Uint8List> open(
  Uint8List sealed,
  X25519KeyAgreement recipient,
) async {
  if (sealed.length < overhead) {
    throw const TspDecryptionException(
      'sealed box shorter than its overhead',
    );
  }
  final epk = Uint8List.sublistView(sealed, 0, 32);
  final shared = await recipient.diffieHellman(Uint8List.fromList(epk));
  X25519.checkContributory(shared);
  final k = _beforenm(Uint8List.fromList(shared));
  final nonce = _nonce(epk, recipient.publicKey);
  final c = Uint8List(16 + sealed.length - 32)
    ..setAll(16, Uint8List.sublistView(sealed, 32));
  final m = Uint8List(c.length);
  try {
    return TweetNaCl.crypto_box_open_afternm(m, c, c.length, nonce, k);
  } on Object catch (e) {
    throw TspDecryptionException(
      'sealed box authentication failed',
      cause: e,
    );
  }
}