Symmetric ciphers
@webbuf/aescbc
Rust/wasm optimized AES+CBC encryption/decryption
Install
npm install @webbuf/aescbc Usage
import { aescbcEncrypt, aescbcDecrypt } from "@webbuf/aescbc";
import { WebBuf } from "@webbuf/webbuf";
import { FixedBuf } from "@webbuf/fixedbuf";
// AES-256 key (32 bytes)
const aesKey = FixedBuf.fromRandom<32>(32);
// Optional: custom IV (16 bytes). If not provided, random IV is generated.
const iv = FixedBuf.fromRandom<16>(16);
// Encrypt
const plaintext = WebBuf.fromUtf8("Hello, world!");
const ciphertext = aescbcEncrypt(plaintext, aesKey, iv);
// Note: IV is prepended to ciphertext
// Decrypt
const decrypted = aescbcDecrypt(ciphertext, aesKey);
console.log(decrypted.toUtf8()); // "Hello, world!" API reference (2 exports)
Functions
aescbcDecrypt
functionDecrypts a ciphertext using AES-CBC with the provided key and IV. If the IV is not provided, the first 16 bytes of the ciphertext are used.
aescbcDecrypt(ciphertext: WebBuf, aesKey: FixedBuf<16> | FixedBuf<24> | FixedBuf<32>): WebBuf aescbcEncrypt
functionEncrypts a plaintext using AES-CBC with the provided key and IV. If the IV is not provided, a random IV is generated.
aescbcEncrypt(plaintext: WebBuf, aesKey: FixedBuf<16> | FixedBuf<24> | FixedBuf<32>, iv?: FixedBuf<16>): WebBuf