cipher-cbc-ts
v1.0.0
Published
A CBC encryption library using aes-js and TypeScript
Maintainers
Readme
cipher-cbc-ts
A CBC encryption library using aes-js, written in TypeScript and designed for Node.js environments.
Features
- AES-256 encryption in CBC mode
- PKCS#7 padding
- Written in TypeScript
- Generates
.d.tstype definitions - Source maps for debugging
- Fully tested with Mocha + Chai
- Compatible with Node.js 20+
Installation
npm install cipher-cbc-ts
## Or clone the repository and build manually:
git clone https://github.com/atandjijero/cipher-cbc-ts.git
cd cipher-cbc-ts
npm install
npm run build
#Usage
#Generate encryption keys using the built-in tool
```bash
node utils/generateKeys.js
## Example output:
const TESTS_KEYS = {
Key: "bbf3e354dbe8d1c92b748e8f67338a3f130aeda4796b702ad3043556e5ac2768",
Iv: "e9211923c55ce6d82603098cd21437d2"
};
## Import and initialize the cipher:
import { cipher } from "cipher-cbc-ts";
const cph = cipher(
Buffer.from(TESTS_KEYS.Key, "hex"),
Buffer.from(TESTS_KEYS.Iv, "hex")
);
## Encrypt and decrypt:
const plainText = "plainText";
## Encrypt
const encrypted = cph.encrypt(plainText);
## Decrypt
const decrypted = cph.decrypt(encrypted);
console.log("Decrypted:", decrypted.text);
## Run all unit tests:
npm test
## Expected output:
CBC Cipher
✔ should encrypt plainText into hex
✔ should decrypt back to original text
Decrypt data
✔ Should decrypt back to original text
Encrypt data
✔ Should encrypt and produce hex
4 passing (8ms)