About secret generator
Secrets for signing tokens, sessions and webhooks must be long, random and private. The generator makes 128 to 512-bit values in hex and Base64.
Choosing a size
- 128 bits is the lowest sensible size.
- 256 bits suits JWT HS256 signing and most session secrets.
- 512 bits is used for HS512 or where extra margin is wanted.
Never reuse
Use a different secret for each purpose and each environment, so exposing one does not weaken the others.
Handle real secrets with care
Keep production keys and secrets in a secrets manager or environment variables, never in source code or chat messages, and rotate them if they may have leaked.
A worked example
A 256-bit secret is 32 bytes, which is 64 hex characters or 44 Base64 characters. That length suits an HS256 JWT signing key. Generating a new secret for each environment means a leak in testing does not affect production.
Where to keep them
- In environment variables or a secrets manager, not in the repository.
- Separate from the application's logs.
- With a documented process for rotating them.
