Generate cryptographically secure hexadecimal passwords and secrets.
Using npm:
npm install -g hexpass
Or run directly with npx:
npx hexpass
hexpass [length]
hexpass --bytes <n>
hexpass --count <n>
hexpass --env <NAME>
hexpass --json
hexpass --help
hexpass --version
- Default:
hexpassoutputs a 32-character hex string. hexpass 64outputs a 64-character string.hexpass 33supports odd lengths (generates the necessary extra byte and truncates to the requested number of hex characters).hexpass --bytes 16uses 16 random bytes (32 hex characters).hexpass 32 --count 5generates 5 secrets, each on its own line.hexpass 48 --env JWT_SECREToutputsJWT_SECRET=<secret>format.hexpass 32 --jsonoutputs a JSON object withlength,bytes, andhexfields (single secret only).
| Option | Description |
|---|---|
length |
Desired hex string length (default 32, max 1024) |
--bytes <n> |
Generate from n bytes (output has n×2 characters) |
--count <n>, -n |
Generate n secrets (default 1, max 100) |
--env <NAME>, -e |
Output as NAME=secret instead of raw secret (only valid for single secret) |
--json, -j |
Output as JSON object (single secret only; incompatible with --env and --copy) |
--copy, -c |
Copy the generated hex string to the clipboard (single secret only) |
--help, -h |
Show usage information |
--version, -v |
Show version number |
--jsonis only supported for single-secret output (--countmust be 1).--envand--jsonare incompatible — use one or the other depending on whether you want an assignment string or structured data.--copyworks only for single-secret output and is incompatible with--json.
# Quickly generate a secret (default 32 chars)
hexpass
# Generate a longer secret
hexpass 64
# Use explicit byte count (generates n * 2 hex chars)
hexpass --bytes 32 > api-key.txt
# Generate and copy a secret (single secret)
hexpass 48 --copy
# Generate multiple secrets in one go
hexpass 32 --count 5
# Output as environment variable format
hexpass 48 --env JWT_SECRET
# Output: JWT_SECRET=a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f
# Output as JSON for automation (single secret)
hexpass 32 --json
# Output: {"length":32,"bytes":16,"hex":"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"}
hexpass always uses crypto.randomBytes() from Node.js for cryptographically strong randomness. No weak sources like Math.random() are used.
The repository includes a small CLI test script used during development. You can exercise common invocations with:
npm test
This runs several hexpass variants to validate behavior (lengths, bytes, --count, --env, and --json).
This README reflects the changes introduced in version 1.0.1 (modular refactor and new CLI options).
MIT