Home / Secret Key Generators / Rails
Rails secret_key_base Generator
Generate a Rails secret_key_base: 128 hex characters, the same format the built-in "rails secret" command produces, entirely in your browser.
Rails secret_key_base Generator
Or generate it with Rails itself
Rails ships a built-in command that does exactly this locally, if you’d rather not paste a secret from a web page:
$ rails secret
# outputs 128 hex characters (64 random bytes)
Set it via ENV["SECRET_KEY_BASE"] or your credentials store. Never commit it directly into config/.
How this tool works
This matches the output format of Rails’ own rails secret command: 128 hexadecimal characters, representing 64 bytes (512 bits) of randomness. This tool generates it via the Web Crypto API’s crypto.getRandomValues() in your browser, the same class of cryptographically secure source rails secret draws from via Ruby’s SecureRandom.hex(64).
- Rails Guides, Configuring Rails Applications: secret_key_base, guides.rubyonrails.org
- MDN Web Docs, Crypto: getRandomValues() method, developer.mozilla.org
Frequently asked questions
What is secret_key_base used for in Rails?
It’s the root key Rails uses to sign and encrypt cookies, sessions, and other sensitive data. If it’s exposed, an attacker could potentially forge session data.
Why 128 hex characters specifically?
That’s the output length of Ruby’s SecureRandom.hex(64): 64 random bytes, each represented as 2 hex characters, which is exactly what the built-in rails secret command generates.