tomSecretsSealBundle function
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]),
};
}