WebBuf WebBuf
Docs

Authenticated encryption

@webbuf/acb3

AES+CBC encryption/decryption with blake3 mac

Install

npm install @webbuf/acb3

Usage

import { acb3Encrypt, acb3Decrypt } from "@webbuf/acb3";
import { WebBuf } from "@webbuf/webbuf";
import { FixedBuf } from "@webbuf/fixedbuf";

// 256-bit key
const key = FixedBuf.fromRandom<32>(32);

// Encrypt with authentication
const plaintext = WebBuf.fromUtf8("Secret message");
const ciphertext = acb3Encrypt(plaintext, key);

// Decrypt and verify
try {
  const decrypted = acb3Decrypt(ciphertext, key);
  console.log(decrypted.toUtf8()); // "Secret message"
} catch (e) {
  console.error("Authentication failed!");
}

API reference (2 exports)

Functions

acb3Decrypt

function

Decrypt data with AES + CBC mode and a Blake3 MAC. ACB3 = AES + CBC + Blake3 Mac

acb3Decrypt(ciphertext: WebBuf, aesKey: FixedBuf<32>): WebBuf

acb3Encrypt

function

Encrypt data with AES + CBC mode and a Blake3 MAC. Good for small amounts of data, such as a short text message. ACB3 = AES + CBC + Blake3 Mac

acb3Encrypt(plaintext: WebBuf, aesKey: FixedBuf<32>, iv?: FixedBuf<16>): WebBuf