An efficient encryption for JSON binary.
npm install objectcipherimport fs from 'node:fs/promises'
import { encrypt, decrypt } from 'objectcipher'
// encrypt
const pass = "husky"
const buffer = encrypt({ msg: "secret" }, pass);
await fs.writeFile("enc.bin", buffer);
// decrypt
const out = decrypt(buffer, pass);
// => {msg: "secret"}Encrypts data using AES-GCM with a password-derived key.
Parameters:
data(unknown) - Any serializable data to encryptpassword(string) - Password for encryption
Returns: Uint8Array - Encrypted data
Example:
const encrypted = encrypt({ secret: "data" }, "myPassword123");Decrypts data encrypted with the encrypt function.
Parameters:
data(Uint8Array) - Encrypted data fromencrypt()password(string) - Password used for encryption
Returns: T - Decrypted data with original type
Example:
const decrypted = decrypt<{ secret: string }>(encrypted, "myPassword123");
console.log(decrypted.secret); // "data"