Both methods produce the same raw material: random bytes from a cryptographically secure generator, encoded as text that a JWT library accepts as an HMAC secret. Randomness is not the deciding factor. The dividing line is what happens after the bytes exist. openssl rand -base64 32 prints 44 characters that include +, / and a padding =, ends with a newline, and leaves every conversion, quoting decision and length check to you. This page generates the key from crypto.getRandomValues in your browser, switches between Hex, Base64 and Base64URL without touching the bytes, keeps the key at or above the minimum for the selected algorithm, and can copy a JWT_SECRET_B64URL line that a .env file takes as it is. Reach for openssl when the key has to be created inside a terminal, a Dockerfile or a CI job; stay here when you want the encoding choice and a paste-ready value. The table below is the short version.
What each method actually does
This page creates a 32-, 48- or 64-byte key for HS256, HS384 or HS512 as soon as it loads, and the byte length can be raised up to 256. Changing Output encoding from Hex to Base64 or Base64URL rewrites the text without changing the key, so one 32-byte secret is 64 Hex characters, 44 Base64 characters or 43 Base64URL characters. Copy key and Copy .env line copy the current encoding; Regenerate replaces the key and drops the old one.
openssl rand takes a byte count and returns that many bytes from the operating system CSPRNG, encoded by the flag you pass. -base64 means standard Base64 with the + and / alphabet and = padding. -hex means lowercase hexadecimal. There is no Base64URL flag, so that alphabet needs a pipe through tr. The command has no idea whether you are making an HS256 key or a key for something else, and it writes the result to stdout with a trailing newline.
JWT secret generator vs openssl rand at a glance
| Aspect | This page | openssl rand |
|---|---|---|
| Random source | Browser Web Crypto, crypto.getRandomValues | OpenSSL CSPRNG fed by the operating system |
| Output encoding | Hex, Base64 or Base64URL, switchable without changing the bytes | -base64 (standard Base64 with +, / and =) or -hex; Base64URL needs a tr pipeline |
| Length control | Algorithm minimum of 32, 48 or 64 bytes, up to 256 bytes | Byte count you type: 32, 48 or 64 for the three HS algorithms |
| Algorithm awareness | HS256, HS384 and HS512 presets | None; a byte count and an encoding flag only |
| Works offline | Yes, once the page has loaded | Yes, the command never uses the network |
| Terminal needed | No, any browser including mobile | Yes; macOS and Linux ship openssl, cmd.exe does not |
| What you paste | Copy the key or copy a ready .env line | Text on stdout, plus quoting and newline cleanup |
| Best for | One-off setup, switching encodings, copying into a dashboard | CI jobs, servers, loops, key rotation scripts |
Why the 44 characters from openssl rand -base64 32 need care
32 random bytes become 44 Base64 characters: A-Z, a-z, 0-9, the two extra symbols + and /, and one = of padding at the end. The key itself is not weak. The trouble is transport and storage, because those symbols are not neutral outside a .env file.
- In a URL, a query parameter or a connection string, + is read as a space by many parsers, / ends a path segment, and = starts the next parameter. The value has to be percent-encoded, or replaced with Base64URL.
- A hand-written config reader that splits a line on every = and keeps the first part silently drops the padding.
- Services disagree on whether a string secret is UTF-8 text or decoded bytes. If one side decodes and the other does not, every signature check fails and the token looks corrupted.
- An
Authorization: Bearerheader accepts these characters, so the header itself is fine; the value only breaks when it travels through a URL or a shell string where the tools on either end interpret it.
The string remains a valid secret. If you want the alphabet that JWT itself uses, convert it instead of regenerating: tr '+/' '-_' maps both special characters and tr -d '=' removes the padding, which turns 44 characters into 43 without changing a single bit.
| Command | Encoding | Characters | Safe where |
|---|---|---|---|
openssl rand -base64 32 | Base64, standard | 44 | Nowhere URL-like without encoding; +, / and = need escaping |
openssl rand -hex 32 | Hex | 64 | URLs, .env files, headers, logs |
openssl rand -base64 32 | tr '+/' '-_' | tr -d '=' | Base64URL | 43 | URLs and the JWT alphabet |
| This page, Base64URL output | Base64URL | 43 | Same bytes, one click, no pipeline |
These are the three commands that cover most JWT work. The third one is a conversion of the first, not a different key:
# HS256, standard Base64, 44 characters
openssl rand -base64 32
# HS256, lowercase hex, 64 characters
openssl rand -hex 32
# HS256, Base64URL without padding, 43 characters
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='
# HS384 and HS512 use 48 and 64 bytes
openssl rand -base64 48
openssl rand -base64 64 | tr -d '\n'
Two output problems show up at larger sizes. OpenSSL ends the output with a newline, so a redirect into a file or an append to .env stores that newline too; command substitution in bash strips it, a file write does not. At 64 bytes the 88 Base64 characters are also wrapped at 64 columns, so an HS512 key copied straight from the terminal can arrive split in half. tr -d '\n' removes both the wrap and the trailing newline and leaves one line of 88 characters.
Getting a JWT secret from this page
- Open the JWT secret key generator. A key is created as soon as the page loads, so there is no empty state to fill in.
- Pick HS256, HS384 or HS512 under Algorithm. The minimum key length follows the algorithm: 32, 48 or 64 bytes.
- Leave Key length at the minimum or raise it, up to 256 bytes. A longer key is allowed but is not required past the hash size.
- Choose Output encoding: Hex, Base64 or Base64URL. The bytes stay identical; only the text changes.
- Use Copy key for the value, or Copy .env line for a
JWT_SECRET_B64URLentry, then choose Regenerate the next time you need a new key.
# Copy .env line writes this shape, with your key as the value
JWT_SECRET_B64URL=your-unpadded-base64url-key
Rename the variable to whatever the framework expects, such as JWT_SECRET_KEY, and keep the file out of version control. A key pasted into the .env file and a key decoded by the app are different keys; pick one rule and apply it everywhere.
Getting the same kind of key with openssl
- Open a terminal. macOS and Linux already have openssl; on Windows, use Git Bash, WSL or the PowerShell alternative in the FAQ.
- Choose the byte count from the algorithm: 32 for HS256, 48 for HS384, 64 for HS512.
- Run
openssl rand -base64 32, or swap in-hexif you want a 64-character value. - Pipe through
tr '+/' '-_' | tr -d '='when the value will sit in a URL or when the library expects Base64URL. - Remove the newline, paste the value into .env or a secret manager, and give every service that signs or verifies tokens the same string.
# Check how many bytes a Base64URL secret really contains
node -e "console.log(Buffer.from(process.env.JWT_SECRET_B64URL, 'base64url').length)"
The command prints 32 for an HS256 key, 48 for HS384 and 64 for HS512. That number is the decoded byte length, which is the key material an app uses when it decodes Base64URL. If it prints 24 for a 32-character secret, the app is decoding the text instead of using those characters as a raw string.
When openssl is the better tool
- The key has to be created where the app runs: a Dockerfile, a bootstrap script, an Ansible task or a CI runner with no browser.
- You need many keys at once, for several environments or services, or a rotation script that replaces them on a schedule.
- The value should never appear in a page or be pasted between windows; a command whose output goes straight into a secret store is shorter to audit.
- You want one command to hand to a teammate in a runbook, with no link to remember.
When this page is the better tool
- You are on a phone or a locked-down machine where installing or opening a terminal is not an option.
- You want the encoding decided for you: Hex, Base64 and Base64URL from the same bytes, with the character counts shown, instead of remembering the tr pipeline.
- You want a .env line that is already Base64URL, so nothing needs quoting or cleanup after the copy.
- You are explaining key length to someone and need HS256, HS384 and HS512 sizes on screen next to the key.
Mistakes that make either key useless
- Using the same secret for development, staging and production. One leaked staging key then signs production tokens.
- Committing the key in source code, in a README or in a screenshot. Generate it once and store it in a secret manager or an untracked .env file.
- Typing a passphrase and calling it random. A memorable string is a dictionary attack target whatever its length.
- Stripping the = padding and then decoding with a strict Base64 decoder, which rejects the shorter string.
- Recording one encoding in .env and a different encoding in the app config, then wondering why verification fails.
- Treating 32 characters as 32 bytes. For HS256 you want 32 random bytes, which is 43 Base64URL characters or 64 hex characters.
Once the key exists, check that a token signed with it verifies: paste the token into the JWT decoder with the key, or sign a test token in the JWT encoder. If you need to convert the key between Hex, Base64 and Base64URL by hand, the Base64 encoder and decoder does it in the browser, and the random string generator covers longer custom lengths.
Frequently asked questions
Which is more random, this generator or openssl rand?
Neither has an edge when both are asked for 32 bytes. This page uses crypto.getRandomValues, the browser Web Crypto random number generator, and openssl rand reads the operating system CSPRNG. Both are built for key material and both give 256 bits of entropy at 32 bytes. A weak JWT secret comes from a short, reused or guessable value, not from choosing one of these two tools over the other.
Can I use the output of openssl rand -base64 32 directly as a JWT secret?
Yes. The 44-character string is 32 random bytes in standard Base64, which is enough for HS256. Decide once how your library reads it: jsonwebtoken and PyJWT use a string secret as UTF-8 text, so the 44 characters themselves become the key, while some setups decode Base64URL to bytes first. Signing and verifying must follow the same rule. Keep the = padding, and percent-encode the value if it goes into a URL, or switch to the 43-character Base64URL form with the tr pipeline shown above.
How do I generate a JWT secret on Windows without OpenSSL?
Use PowerShell, which reaches the same operating system CSPRNG through .NET. In PowerShell 7.2 or later, running [Convert]::ToBase64String([System.Security.Cryptography.RandomNumberGenerator]::GetBytes(32)) prints a 44-character Base64 secret, and changing 32 to 48 or 64 matches HS384 and HS512. Windows PowerShell 5.1 needs the byte array form instead, New-Object byte[] 32 filled through RandomNumberGenerator.Create. cmd.exe has neither, and Git for Windows or WSL adds openssl if you prefer the command line shown above. You can also generate the key on this page in any browser and skip the install.
Do I need to use both this page and openssl?
No. One generated key is enough, and making the same secret twice is a common way to end up with two keys in two configs. Create the key once by whichever method is at hand, store it in one place such as an untracked .env file or a secret manager, and give every service that signs or verifies tokens that same value. This page is still useful afterwards for switching the encoding or checking character counts, but it does not need to be part of deployment.
Why does my key change length when I switch encodings?
The bytes stay the same and only the text changes. Hex uses two characters per byte, Base64 packs three bytes into four characters and adds padding, and Base64URL drops that padding. So a 32-byte HS256 key is 64 characters in Hex, 44 in Base64 and 43 in Base64URL; a 48-byte HS384 key is 96, 64 and 64; a 64-byte HS512 key is 128, 88 and 86. A 32-character text string chosen for HS256 is 32 bytes of text, roughly 190 bits, not the 256 bits of 32 random bytes.
Want to see where a key like this lands? Use the browser-based JWT secret generator and the JWT token decoder next.
Related guides
- How long should a JWT secret be? HS256, HS384 and HS512 sizes
- Generate a JWT secret in Node.js
- Where to store a JWT secret and how often to rotate it
- Is an online JWT secret generator safe?