crypt-the-json
v1.0.1
Published
A utility for encrypting and decrypting JSON objects with selective field encryption
Downloads
25
Maintainers
Readme
JSON Object Crypto
A utility for encrypting and decrypting JSON objects with selective field encryption. This package allows you to encrypt specific fields in your JSON objects while keeping others in plain text.
Features
- Encrypt and decrypt JSON objects
- Selective field encryption
- Support for nested objects and arrays
- Uses AES-256-CBC encryption by default
- Configurable encryption algorithm and encoding
Installation
npm install crypt-the-jsonUsage
const crypto = require("crypt-the-json");
// Example object
const data = {
name: "John Doe",
email: "[email protected]",
password: "secret123",
address: {
street: "123 Main St",
city: "New York",
},
};
// Encrypt specific fields
const encrypted = crypto.encrypt(data, "your-secret-key");
// Decrypt the encrypted object
const decrypted = crypto.decrypt(encrypted, "your-secret-key");API
encrypt(object, password)
Encrypts an object with the given password.
Parameters
object(Object): The JSON object to encryptpassword(string): The encryption passwordconfig(Object): Configuration optionsalgorithm(string): Encryption algorithm (default: 'aes-256-cbc')encoding(string): Output encoding (default: 'hex')keys(string[]): Optional array of keys to encrypt (if not provided, encrypts all fields)
decrypt(object, password)
Decrypts an object with the given password.
Parameters
object(Object): The JSON object to decryptpassword(string): The decryption passwordconfig(Object): Configuration optionsalgorithm(string): Encryption algorithm (default: 'aes-256-cbc')encoding(string): Input encoding (default: 'hex')keys(string[]): Optional array of keys to decrypt (if not provided, decrypts all fields)
License
MIT
