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

How this page and openssl rand differ when you need an HMAC secret
AspectThis pageopenssl rand
Random sourceBrowser Web Crypto, crypto.getRandomValuesOpenSSL CSPRNG fed by the operating system
Output encodingHex, Base64 or Base64URL, switchable without changing the bytes-base64 (standard Base64 with +, / and =) or -hex; Base64URL needs a tr pipeline
Length controlAlgorithm minimum of 32, 48 or 64 bytes, up to 256 bytesByte count you type: 32, 48 or 64 for the three HS algorithms
Algorithm awarenessHS256, HS384 and HS512 presetsNone; a byte count and an encoding flag only
Works offlineYes, once the page has loadedYes, the command never uses the network
Terminal neededNo, any browser including mobileYes; macOS and Linux ship openssl, cmd.exe does not
What you pasteCopy the key or copy a ready .env lineText on stdout, plus quoting and newline cleanup
Best forOne-off setup, switching encodings, copying into a dashboardCI 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.

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.

What each command prints for a 256-bit HS256 key
CommandEncodingCharactersSafe where
openssl rand -base64 32Base64, standard44Nowhere URL-like without encoding; +, / and = need escaping
openssl rand -hex 32Hex64URLs, .env files, headers, logs
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='Base64URL43URLs and the JWT alphabet
This page, Base64URL outputBase64URL43Same 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

  1. 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.
  2. Pick HS256, HS384 or HS512 under Algorithm. The minimum key length follows the algorithm: 32, 48 or 64 bytes.
  3. 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.
  4. Choose Output encoding: Hex, Base64 or Base64URL. The bytes stay identical; only the text changes.
  5. Use Copy key for the value, or Copy .env line for a JWT_SECRET_B64URL entry, 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

  1. Open a terminal. macOS and Linux already have openssl; on Windows, use Git Bash, WSL or the PowerShell alternative in the FAQ.
  2. Choose the byte count from the algorithm: 32 for HS256, 48 for HS384, 64 for HS512.
  3. Run openssl rand -base64 32, or swap in -hex if you want a 64-character value.
  4. Pipe through tr '+/' '-_' | tr -d '=' when the value will sit in a URL or when the library expects Base64URL.
  5. 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

When this page is the better tool

Mistakes that make either key useless

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.

Generate a JWT secret key

Want to see where a key like this lands? Use the browser-based JWT secret generator and the JWT token decoder next.