Skip to content

seanghay/objectcipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An efficient encryption for JSON binary.

Install

npm install objectcipher

Usage

import 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"}

API

encrypt(data, password)

Encrypts data using AES-GCM with a password-derived key.

Parameters:

  • data (unknown) - Any serializable data to encrypt
  • password (string) - Password for encryption

Returns: Uint8Array - Encrypted data

Example:

const encrypted = encrypt({ secret: "data" }, "myPassword123");

decrypt(data, password)

Decrypts data encrypted with the encrypt function.

Parameters:

  • data (Uint8Array) - Encrypted data from encrypt()
  • 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"

About

An efficient encryption for JSON binary.

Resources

Stars

Watchers

Forks