tomSecretsSealBundle function

Future<Map<String, String>> tomSecretsSealBundle({
  1. required List<int> bundleKey,
  2. required String vault,
  3. required int serviceStart,
  4. required List<int> plaintext,
  5. List<int>? nonce,
})

Seals plaintext for vault under bundleKey: the bundle object of unlock (nonce, ciphertext with the tag, both base64). nonce is random unless given (test vectors).

Implementation

Future<Map<String, String>> tomSecretsSealBundle({
  required List<int> bundleKey,
  required String vault,
  required int serviceStart,
  required List<int> plaintext,
  List<int>? nonce,
}) async {
  final n = nonce ?? tomSecretsRandomBytes(tomSecretsBundleNonceBytes);
  final box = await _aesGcm.encrypt(
    plaintext,
    secretKey: SecretKeyData(bundleKey),
    nonce: n,
    aad: tomSecretsBundleAad(vault, serviceStart),
  );
  return {
    'nonce': base64.encode(n),
    'ciphertext': base64.encode([...box.cipherText, ...box.mac.bytes]),
  };
}