npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

env-encryption

v1.11.0

Published

A utility for encrypting and decrypting environment variables in frontend projects, inspired by Laravel's encryption methods.

Downloads

35

Readme

Env Encryption

Env Encryption is a command-line tool designed for encrypting and decrypting environment variables within frontend projects. Drawing inspiration from Laravel's encryption techniques, it offers a secure means of safeguarding sensitive environment configurations in client-side applications while enabling their safe inclusion in your version control system (Git).

Installation

You can install the env-encryption package globally using npm:

npm install -g env-encryption

Alternatively, you can use it on the fly with npx, prefixing the commands with npx:

npx env-encryption 

Usage

To use Env Encryption, run it from the command line with the following options:

env-encryption [command] --key <encryption-key> --env <environment> --filename <filename> [--force] [--cipher <cipher-algorithm>]
  • [command]: Specify the operation to perform. Use either encrypt or decrypt.
  • --key <encryption-key>: Specify the encryption key. If not provided, a random key will be generated.
  • --env <environment>: Specify the environment name.
  • --filename <filename>: Specify the target filename for decrypting (optional).
  • --force: Overwrite existing files if they already exist (optional).
  • --cipher <cipher-algorithm>: Specify the encryption cipher algorithm. The default is aes-256-cbc (optional).

Examples

Encrypting Environment Variables

To encrypt environment variables, follow these steps:

  1. Open your terminal.

  2. Navigate to the root directory of your project.

  3. Make sure a .env file is present for the env your encrypting (e.g., .env.production).

  4. Run the following command, replacing the placeholders with your actual data:

    env-encryption encrypt --key <encryption-key> --env <environment-name> [--force] [--cipher <cipher-algorithm>]
    • <encryption-key>: Specify the encryption key. If not provided, a random key will be generated.
    • <environment-name>: Specify the environment name.
    • --force (optional): Use this flag to overwrite existing encrypted files.
    • --cipher <cipher-algorithm> (optional): Specify the encryption cipher algorithm (default is aes-256-cbc).

    Example:

    env-encryption encrypt --key mySecretKey --env production --force 
  5. If you didn't specify an encryption key, the tool will generate a random key and display it in the terminal.

  6. The encrypted environment file (e.g., .env.production.encrypted) will be created in your project directory.

Decrypting Environment Variables

To decrypt environment variables, follow these steps:

  1. Open your terminal.

  2. Navigate to the root directory of your project.

  3. Make sure a .env file is present for the env your encrypting (e.g., .env.production.encrypted).

  4. Run the following command, replacing the placeholders with your actual data:

    env-encryption decrypt --key <encryption-key> --env <environment-name> --filename <filename> [--force] [--cipher <cipher-algorithm>]
    • <encryption-key>: Specify the decryption key.
    • <environment-name>: Specify the environment name.
    • <filename>: Specify the target filename.
    • --force (optional): Use this flag to overwrite existing files.
    • --cipher <cipher-algorithm> (optional): Specify the encryption cipher algorithm (default is aes-256-cbc).

    Example:

    env-encryption decrypt --key mySecretKey --env production --filename .env --force 
  5. The decrypted environment file (e.g., .env) will be created in your project directory.

Commands

Encrypt

To encrypt an environment file, use the encrypt command:

env-encryption encrypt --key <encryption-key> --env <environment> [--force] [--cipher <cipher-algorithm>]
  • <encryption-key>: The encryption key (mandatory).
  • <environment>: The environment name (mandatory).
  • --force: Overwrite existing encrypted files (optional).
  • --cipher <cipher-algorithm>: Specify the encryption cipher algorithm. The default is aes-256-cbc (optional).

If you omit the --key option, a random key will be generated and displayed.

Decrypt

To decrypt an environment file, use the decrypt command:

env-encryption decrypt --key <encryption-key> --env <environment> --filename <filename> [--force] [--cipher <cipher-algorithm>]
  • <encryption-key>: The decryption key (mandatory).
  • <environment>: The environment name (mandatory).
  • <filename>: The target filename where the content will be written (optional).
  • --force: Overwrite existing files if they already exist (optional).
  • --cipher <cipher-algorithm>: Specify the encryption cipher algorithm. The default is aes-256-cbc (optional).

Error Handling

The utility includes basic error handling to ensure data integrity and security:

  • It checks for the existence of input and output files.
  • It verifies the encryption key's format and handles base64 encoding.
  • It provides warnings when overwriting existing files.

Logging

Logs are generated for each operation, including a timestamp and log level (INFO, SUCCESS, WARNING, ERROR). Logs are displayed in the terminal for monitoring and debugging.

Dependencies

The utility uses the following Node.js modules:

  • optimist for command-line argument parsing.
  • fs for file system operations.
  • crypto for cryptographic functions.
  • chalk for colorized console output.

License

This project is licensed under the MIT License.

Author

  • Jelle Nijhof