Neurosis Prevention Mechanism

    aead-stream
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.7 • Public • Published

    aead-stream

    Authenticated encryption on arbitrary large files

    aead-stream is a simple API to perform authenticated symmetric encrytion on data of arbitrary size.

    Install

    npm install aead-stream
    

    Usage

    encrypt(key, plaintext[, options])

    Click to view example
    const { encrypt } = require("aead-stream");
    const { createReadStream } = require("fs");
    
    /**
     * @param {Uint8Array} key 256 bit key material
     * @param {string} filepath a file path
     */
    async function encyptFile(key, filepath) {
      const readStream = createReadStream(filepath);
    
      for await (const encryptedChunk of encrypt(key, readStream)) {
        // store encryptedChunk - it is a Uint8Array with at most 64K size
      }
    }

    decrypt(key, ciphertext[, options])

    Click to view example
    const { decrypt } = require("aead-stream");
    const { createReadStream } = require("fs");
    
    /**
     * @param {Uint8Array} key 256 bit key material
     * @param {string} filepath a file path to an encrypted file
     */
    async function decyptFile(key, filepath) {
      const readStream = createReadStream(filepath);
    
      for await (const plain of decrypt(key, readStream)) {
        // process plain - a Uint8Array
      }
    }

    Default options

    • algorithm "chacha20-poly1305",
    • nonceLength 12,
    • authTagLength 16,
    • chunkSize 64 * 1024 (64K)

    Install

    npm i aead-stream

    DownloadsWeekly Downloads

    23

    Version

    0.0.7

    License

    MIT

    Unpacked Size

    11.9 kB

    Total Files

    13

    Last publish

    Collaborators

    • fichtelmax