A Laravel-inspired, zero-dependency CLI and Library for env file encryption
npm install crenvocrenvo = crypto + env
php artisan key:generate, crenvo brings secure environment variable encryption to the Node.js ecosystem. By utilizing native Node.js crypto capabilities, this package allows you to manage sensitive secrets without external dependencies.
ENC_CODE in your env file.
.env in project root).
setCode | (envFile?: string) => void | Create an ENC_CODE in your env file. |
getCode | (envFile?: string) => Promise | Retrieve the value of ENC_CODE. |
getKeyIv | (envFile?: string) => Promise | Retrieve the Encryption KEY and IV. |
encrypt | (str: string, envFile?: string) => Promise | Encrypt a string value. |
encryptAndSet | (str: string, field: string, envFile?: string) => Promise | Encrypt and write to a specific field. |
decrypt | (str: string, envFile?: string) => Promise | Decrypt a string value. |
typescript
import { encrypt, decrypt, setCode } from 'crenvo';
async function example() {
// Initialize key if not present
await setCode('.env');
// Encrypt a value
const encrypted = await encrypt("my_secret_key");
console.log(Encrypted: ${encrypted});
// Decrypt the value
const original = await decrypt(encrypted);
console.log(Original: ${original}`);