@webbuf/acb3
v3.5.0
Published
AES+CBC encryption/decryption with blake3 mac for web, node.js, deno and bun.
Maintainers
Readme
@webbuf/acb3
Authenticated encryption using AES-CBC with BLAKE3 MAC.
ACB3 = AES + CBC + Blake3 MAC
Installation
npm install @webbuf/acb3Usage
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!");
}How It Works
Encryption:
- Encrypts plaintext with AES-CBC (random IV)
- Computes BLAKE3 MAC over the ciphertext
- Returns:
MAC (32 bytes) || IV (16 bytes) || encrypted data
Decryption:
- Extracts and verifies the MAC
- Throws if MAC doesn't match (tampered data)
- Decrypts and returns plaintext
API
| Function | Description |
| ---------------------------------- | ------------------------------------------- |
| acb3Encrypt(plaintext, key, iv?) | Encrypt with MAC. Optional custom IV. |
| acb3Decrypt(ciphertext, key) | Decrypt and verify. Throws on auth failure. |
License
MIT
