A simple Node.js utility for encrypting and decrypting JSON data using AES-256-CBC encryption.
- Encrypt JSON data with AES-256-CBC encryption
- Decrypt encrypted data back to JSON
npm install
Edit src/config.ts
to modify the sample JSON data:
export const SAMPLE_JSON = {
name: "Simon",
website: "https://smarenkov.github.io",
};
npm run encrypt
This will:
- Generate a random 32-byte key and 16-byte IV
- Encrypt the sample JSON data
- Output the encryption details including the key, IV, and encrypted data
npm run decrypt -- -privateKeyHex <key> -ivHex <iv> -encryptedHex <encryptedData>
For example:
npm run decrypt -- -privateKeyHex 7cea2a87a699ec9d069894454c6af2fa85ba35430e94e81ef9df149a684aecb1 -ivHex 26e1e513bd134ab173d66f380710a279 -encryptedHex 48595446c4c79909526aa6195a5d5115e6623c6967a1fb34339d239ef5447f50958a81128c6d994510ead135938603e73db947f771e27c28a4d879f97da4fcf5
This will:
- Use the provided key, IV, and encrypted data
- Decrypt the data back to JSON
- Output the decrypted JSON object