Appearance
@pqc-sdk/core / encryptStream
Function: encryptStream()
encryptStream(
publicKey,plaintext,options?):AsyncGenerator<Uint8Array<ArrayBufferLike>>
Hybrid streaming encryption: like encrypt, but for payloads too large to hold in memory at once. Encapsulates one KEM secret per stream (fresh, single-use, same as encrypt) and seals fixed-size chunks of plaintext under it, using age's STREAM chunk framing (docs/serialization-format.md §9). Bounded memory: roughly one chunk at a time, independent of total payload size.
Yields the 3-byte header and KEM ciphertext first, then one sealed chunk per plaintext chunk. Concatenating everything yielded reproduces the full wire format §9 describes.
chunkSize (advanced, rarely needed) defaults to 64 KiB — see StreamOptions.
Parameters
publicKey
plaintext
AsyncIterable<Uint8Array<ArrayBufferLike>>
options?
Returns
AsyncGenerator<Uint8Array<ArrayBufferLike>>
Example
ts
import { pqc } from '@pqc-sdk/core';
const pair = await pqc.keys.generate();
async function* source() {
yield new TextEncoder().encode('streamed data');
}
const parts: Uint8Array[] = [];
for await (const chunk of pqc.encryptStream(pair.publicKey, source())) {
parts.push(chunk);
}