stream library

Streaming authenticated encryption based on age's STREAM construction.

https://eprint.iacr.org/2015/189.pdf

Plaintext is split into 64 KiB chunks, each sealed with ChaCha20-Poly1305 under a nonce that counts up and marks the final chunk, so truncation and reordering are detected. Both functions take and return whole buffers.

import 'dart:convert';

import 'package:darkbio_crypto/rand.dart' as rand;
import 'package:darkbio_crypto/stream.dart' as stream;

void example() {
  // Never reuse a key across streams
  final key = rand.bytes(32);

  final ciphertext = stream.encrypt(key: key, plaintext: utf8.encode('hello stream'));
  final plaintext = stream.decrypt(key: key, ciphertext: ciphertext);
  assert(utf8.decode(plaintext) == 'hello stream');
}

Functions

decrypt({required Uint8List key, required Uint8List ciphertext}) → Uint8List
Decrypts a STREAM ciphertext under the 32-byte key it was encrypted with.
encrypt({required Uint8List key, required Uint8List plaintext}) → Uint8List
Encrypts plaintext as a STREAM under the 32-byte key.