A secure dotenv–from the creator of dotenv

Usage
Encrypt
$ curl -sfS 'https://dotenvx.sh' | sh
$ dotenvx encrypt
◈ encrypted (.env)
Your .env values become ciphertext. The private key that unlocks them goes in .env.keys.
Commit
$ git add .env
$ git commit -m "encrypt .env"
Your encrypted .env travels with your code. Keep .env.keys out of Git. The secrets and the key that unlocks them stay separate.
Ship
$ dotenvx run -- node index.js
⟐ injected env (2) from .env
Locally, the key is read from .env.keys. Dotenvx decrypts your secrets and injects them into your app at runtime.
For production, use a separate encrypted file and key. See the production quickstart.
Dual-Breach Required
Decrypting .env values at rest requires both the encrypted file and its matching private key.
Dotenvx lets you keep the file in Git and the key in a separate store. An attacker who gains access to either store alone gets only one of the two.
In the whitepaper’s illustrative model, separating the encrypted .env file from its private key lowers the annual chance of exposing stored secrets from 1% to 0.005%, a 99.5% reduction, assuming the two breaches are independent. See the calculation on page 13.

Design Principles
Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.
We chose Git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world-class one is right there at your fingertips.
We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.
Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging Git's distribution advantages while still following the twelve-factor config - by separating the decryption key from the code (environment).
It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.
The result is a system built entirely from primitives developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. Here’s the unlock. All this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.
Key Custody
By default, you do. Keep the private key on your machine for development and in your deployment environment for production.
When you need to manage access across a team, Armor adds managed key custody, approvals, and auditing. Or choose from other custody options.
Dotenvx Adoption
- 22 million weekly npm installs
- Google, NASA, AWS, and CrowdStrike
- The previous Head of DevSecOps at Zoom