{"_id":"json-encrypt-cli","name":"json-encrypt-cli","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"json-encrypt-cli","version":"1.0.0","description":"A CLI tool to encrypt JSON files with various algorithms","main":"index.js","bin":{"json-encrypt":"bin/enc.js","json-decrypt":"bin/dec.js","json-batch-encrypt":"bin/batch-enc.js","json-batch-decrypt":"bin/batch-dec.js"},"scripts":{"start":"node bin/enc.js","test":"node test-encryption.js","demo":"node bin/enc.js test/accounts.prep.json --alg aes-256-cbc --secret demoSecret123","demo-decrypt":"node bin/dec.js test/accounts.prep.enc --algorithm aes-256-cbc --secret demoSecret123 --overwrite","demo-env":"node bin/enc.js test/accounts.prep.json","demo-env-decrypt":"node bin/dec.js test/accounts.prep.enc --overwrite","batch-encrypt":"node bin/batch-enc.js","batch-decrypt":"node bin/batch-dec.js","demo-batch":"node bin/batch-enc.js test --recursive","demo-batch-decrypt":"node bin/batch-dec.js test --recursive --overwrite","setup-git-hooks":"node examples/setup-git-hooks.js"},"keywords":["encryption","json","cli","crypto"],"author":"","license":"MIT","dependencies":{"@clack/prompts":"^0.7.0","commander":"^11.1.0","dotenv":"^16.3.1"},"engines":{"node":">=14.0.0"},"_id":"json-encrypt-cli@1.0.0","gitHead":"b9f236bc1b99f7346bda6c6178d3686e214a71f1","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-cKgqIdLHgEa4t+8UBCfMgT92G2dzYCFaDb8Xrqjd1JrElTHjfPlRO1iRI6qYDKIJAyanE2mgiVCSyWwvigp9tQ==","shasum":"f146a13617eae2172b4d481487eeafb3d97b1af7","tarball":"https://registry.npmjs.org/json-encrypt-cli/-/json-encrypt-cli-1.0.0.tgz","fileCount":27,"unpackedSize":99268,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDqovh1mQxisABP9tTKZFz9wt8IYnBRXlsmfyrzCWVWeAiEArs2R0fv1hnoay22DOvnFujr9h+tIV3Thzarjoil4oLc="}]},"_npmUser":{"name":"latiasthinh","email":"thomas.ng4542@gmail.com"},"directories":{},"maintainers":[{"name":"latiasthinh","email":"thomas.ng4542@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-encrypt-cli_1.0.0_1756222513516_0.6300903756668073"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-26T15:35:13.422Z","1.0.0":"2025-08-26T15:35:13.733Z","modified":"2025-08-26T15:35:14.015Z"},"maintainers":[{"name":"latiasthinh","email":"thomas.ng4542@gmail.com"}],"description":"A CLI tool to encrypt JSON files with various algorithms","keywords":["encryption","json","cli","crypto"],"license":"MIT","readme":"# JSON Encrypt CLI\n\nA command-line tool to encrypt JSON files using various encryption algorithms with customizable secret keys.\n\n## Features\n\n- 🔐 **Multiple AES Algorithms**: Support for AES-128, AES-192, and AES-256 with CBC and GCM modes\n- 🎯 **Dual Usage Modes**: Command-line for automation, interactive for ease of use\n- 🔑 **Secure Key Derivation**: Uses scrypt for robust key generation from passwords\n- 🎲 **Random IV Generation**: Each encryption uses a unique initialization vector\n- 📁 **Structured Output**: Creates `.enc` files with organized encrypted data\n- 📦 **Batch Processing**: Encrypt/decrypt entire directories of JSON files at once\n- 📝 **Auto-generated Examples**: Provides TypeScript decryption code examples\n- 🛡️ **Data Integrity**: GCM mode includes authentication tags for tamper detection\n- 🔒 **Algorithm Concealment**: Encrypted files don't expose the algorithm used for maximum security\n- ⚙️ **Environment Configuration**: Set default algorithm and secret key via `.env` file for convenience\n\n## Installation\n\n```bash\nnpm install\n```\n\n## Configuration\n\n### Environment Variables (.env)\n\nYou can set default values for algorithm and secret key by creating a `.env` file in your project root:\n\n```bash\n# Copy .env.example to .env and customize\ncp .env.example .env\n```\n\nExample `.env` file:\n```bash\n# Default encryption algorithm\nENC_ALGORITHM=aes-256-gcm\n\n# Default secret key\nENC_SECRET=your-default-secret-key-here\n```\n\n**Benefits of using .env:**\n- 🚀 **Faster workflow**: No need to type algorithm and secret every time\n- 🔒 **Consistent settings**: Same algorithm and key across all operations\n- 💼 **Team collaboration**: Share `.env.example` with your team (never commit actual `.env`!)\n- 🎯 **Selective override**: Command line arguments still override .env defaults\n\n**Security Note:** Never commit your `.env` file to version control! Add `.env` to your `.gitignore`.\n\n## Usage\n\n### Encryption\n\n#### Interactive Mode (Recommended)\n\nSimply run the command with a JSON file path:\n\n```bash\nnpx json-encrypt path/to/your/file.json\n# or\nnode bin/enc.js path/to/your/file.json\n```\n\nThe tool will prompt you to:\n- Choose an encryption algorithm\n- Enter a secret key\n- Decide whether to generate a decryption example\n\n#### Command Line Mode\n\nFor automated scripts or when you know exactly what you want:\n\n```bash\n# With explicit parameters\nnpx json-encrypt path/to/your/file.json --alg aes-256-cbc --secret your-secret-key\n# or\nnode bin/enc.js path/to/your/file.json --alg aes-256-cbc --secret your-secret-key\n\n# Using .env defaults (if configured)\nnpx json-encrypt path/to/your/file.json\n# or\nnode bin/enc.js path/to/your/file.json\n\n# Mix: override algorithm but use .env secret\nnpx json-encrypt path/to/your/file.json --alg aes-128-cbc\n```\n\n### Decryption\n\n#### Interactive Mode (Recommended)\n\n```bash\nnpx json-decrypt path/to/your/file.enc\n# or\nnode bin/dec.js path/to/your/file.enc\n```\n\nThe tool will prompt you to:\n- Enter the algorithm used for encryption\n- Enter the secret key used for encryption\n- Choose whether to overwrite existing files\n\n#### Command Line Mode\n\n```bash\n# With explicit parameters\nnpx json-decrypt path/to/your/file.enc --algorithm aes-256-cbc --secret your-secret-key\n# or\nnode bin/dec.js path/to/your/file.enc --algorithm aes-256-cbc --secret your-secret-key --overwrite\n\n# Using .env defaults (if configured)\nnpx json-decrypt path/to/your/file.enc --overwrite\n# or\nnode bin/dec.js path/to/your/file.enc --overwrite\n\n# Mix: override algorithm but use .env secret\nnpx json-decrypt path/to/your/file.enc --algorithm aes-128-cbc --overwrite\n```\n\n#### Encryption Options\n\n- `--alg <algorithm>`: Encryption algorithm (default: aes-256-cbc)\n- `--secret <key>`: Secret key for encryption\n- `--no-example`: Skip generating the decryption example file\n\n#### Decryption Options\n\n- `--algorithm <alg>`: Encryption algorithm used (required for command line mode)\n  - Supported: `aes-128-cbc`, `aes-192-cbc`, `aes-256-cbc`, `aes-128-gcm`, `aes-192-gcm`, `aes-256-gcm`\n- `--secret <key>`: Secret key used for encryption (required for command line mode)\n- `--overwrite`: Overwrite output file if it exists\n\n### Supported Algorithms\n\n- `aes-256-cbc` (default)\n- `aes-192-cbc`\n- `aes-128-cbc`\n- `aes-256-gcm`\n- `aes-192-gcm`\n- `aes-128-gcm`\n\n## Output\n\nThe tool will:\n1. Create an encrypted file with `.enc` extension (e.g., `data.json` → `data.enc`)\n2. Generate a TypeScript example file (`decryption.example.ts`) showing how to decrypt the file\n\nThe encrypted `.enc` file contains:\n- Initialization Vector (IV)\n- Encrypted data\n- Authentication tag (for GCM modes)\n- **Note**: The algorithm is intentionally hidden for security - only you know which algorithm was used\n\n## Examples\n\n### Encryption Example\n\n```bash\n# Encrypt accounts.json with AES-256-CBC\nnode bin/enc.js accounts.json --alg aes-256-cbc --secret mySecretKey123\n\n# Output:\n# ✅ Encryption completed successfully!\n# 📁 Encrypted file: accounts.enc\n# 📄 Decryption example: decryption.example.ts\n```\n\n### Decryption Example\n\n```bash\n# Decrypt accounts.enc back to JSON\nnode bin/dec.js accounts.enc --algorithm aes-256-cbc --secret mySecretKey123 --overwrite\n\n# Output:\n# ✅ Decryption completed successfully!\n# 📁 Decrypted file: accounts.json\n# 🔐 Algorithm used: aes-256-cbc\n```\n\n### Round-trip Example\n\n```bash\n# 1. Encrypt a JSON file\nnode bin/enc.js data.json --alg aes-256-gcm --secret mySecret123\n\n# 2. Decrypt it back\nnode bin/dec.js data.enc --algorithm aes-256-gcm --secret mySecret123\n\n# 3. Verify the content matches the original\n```\n\n## Security Notes\n\n- Use strong, unique secret keys\n- Keep your secret keys secure and never commit them to version control\n- The same secret key is required for decryption\n- GCM algorithms provide authenticated encryption for additional security\n\n## Decryption Methods\n\n### 1. CLI Tool (Recommended)\n\nUse the `json-decrypt` command to decrypt files directly:\n\n```bash\nnpx json-decrypt file.enc --algorithm aes-256-cbc --secret yourSecretKey\n# or\nnode bin/dec.js file.enc --algorithm aes-256-cbc --secret yourSecretKey\n```\n\n### 2. Programmatic Decryption\n\nUse the generated `decryption.example.ts` file as a reference to decrypt your files programmatically in your own code.\n\n### 3. Batch Processing\n\n**Encrypt entire directories:**\n```bash\n# Using npx (recommended)\nnpx json-batch-encrypt /path/to/directory\nnpx json-batch-encrypt /path/to/directory --recursive\n\n# Using node directly\nnode bin/batch-enc.js /path/to/directory\nnode bin/batch-enc.js /path/to/directory --recursive\n\n# Use specific algorithm and secret\nnpx json-batch-encrypt /path/to/directory --alg aes-256-gcm --secret mySecret\n\n# Use .env defaults (recommended)\nnpx json-batch-encrypt /path/to/directory --recursive\n```\n\n**Decrypt entire directories:**\n```bash\n# Using npx (recommended)\nnpx json-batch-decrypt /path/to/directory --overwrite\nnpx json-batch-decrypt /path/to/directory --recursive --overwrite\n\n# Using node directly\nnode bin/batch-dec.js /path/to/directory --overwrite\nnode bin/batch-dec.js /path/to/directory --recursive --overwrite\n\n# Use specific algorithm and secret\nnpx json-batch-decrypt /path/to/directory --algorithm aes-256-gcm --secret mySecret --overwrite\n```\n\n### 4. Git Integration & Automation\n\n#### 🔗 Pre-commit Hook Setup\n\nAutomatically encrypt sensitive JSON files before commits:\n\n**1. Install husky (if not already installed):**\n```bash\nnpm install --save-dev husky\nnpx husky install\n```\n\n**2. Quick setup (recommended):**\n```bash\n# Interactive setup script\nnode examples/setup-git-hooks.js\n```\n\n**3. Manual husky setup:**\n```bash\nnpx husky add .husky/pre-commit \"npx json-batch-encrypt src/config --recursive && git add .\"\n```\n\n**4. Manual hook setup:**\nCopy `examples/pre-commit` to `.git/hooks/pre-commit` and make it executable:\n```bash\ncp examples/pre-commit .git/hooks/pre-commit\nchmod +x .git/hooks/pre-commit\n```\n\n#### 🚀 CI/CD Integration\n\n**For deployment workflows (when JSON files aren't committed):**\n```bash\n# GitHub Actions\ncp examples/github-actions-deploy.yml .github/workflows/deploy.yml\n\n# Azure DevOps Pipeline\ncp examples/azure-pipeline.yml azure-pipelines.yml\n\n# Copy Docker example\ncp examples/Dockerfile.example Dockerfile\n\n# Read comprehensive CI/CD guide\ncat examples/CICD-GUIDE.md\n```\n\n**Set up GitHub secrets:**\n1. Go to your repository Settings → Secrets and variables → Actions\n2. Add `ENCRYPTION_SECRET` with your encryption key\n\n**Deployment strategies:**\n- **Runtime decryption**: Decrypt files when application starts\n- **Build-time decryption**: Decrypt during CI/CD build process\n- **External secrets**: Use Kubernetes/cloud secret management\n\n**Key workflow features:**\n- Decrypts `.enc` files during deployment\n- Supports multiple environments with different secrets\n- Includes Docker multi-stage builds\n- Provides AWS Lambda deployment examples\n- Ensures cleanup of decrypted files for security\n\n#### 📋 Workflow Recommendations\n\n1. **Development**: Keep `.json` files unencrypted for easy editing\n2. **Pre-commit**: Automatically encrypt sensitive files\n3. **Repository**: Store only `.enc` files for sensitive data\n4. **Deployment**: Decrypt files in CI/CD pipeline\n\n### 5. npm Scripts\n\n```bash\n# Setup and configuration\nnpm run setup-git-hooks     # Interactive Git hooks setup\n\n# Test the tools\nnpm test\n\n# Demo encryption (explicit parameters)\nnpm run demo\n\n# Demo decryption (explicit parameters)\nnpm run demo-decrypt\n\n# Demo encryption using .env defaults\nnpm run demo-env\n\n# Demo decryption using .env defaults\nnpm run demo-env-decrypt\n\n# Batch processing demos\nnpm run demo-batch          # Batch encrypt test directory\nnpm run demo-batch-decrypt  # Batch decrypt test directory\n```","readmeFilename":"README.md","_rev":"1-f906aa85206f125c74be2015d653349e"}