encrypt function
Stream<List<int> >
encrypt(
- Stream<
List< payload,int> > - List<
AgeRecipient> recipients, { - AgeRandom random = const AgeRandom(),
- SimpleKeyPair? keyPair,
Implementation
Stream<List<int>> encrypt(
Stream<List<int>> payload, List<AgeRecipient> recipients,
{AgeRandom random = const AgeRandom(), SimpleKeyPair? keyPair}) async* {
_logger.fine('Encrypting to ${recipients.length} recipients');
final symmetricFileKey = random.bytes(16);
final stanzas =
await Future.wait<AgeStanza>(recipients.map((recipient) async {
return AgePlugin.stanzaCreate(recipient, symmetricFileKey, keyPair);
}));
if (stanzas.isEmpty) {
throw Exception('Could not encrypt to any recipient!');
}
final header = await AgeHeader.create(stanzas, symmetricFileKey);
final payloadNonce = random.bytes(16);
yield (await header.serialize()).codeUnits;
yield [0x0a];
yield* _encryptPayload(payload,
symmetricFileKey: symmetricFileKey, payloadNonce: payloadNonce);
}