AES Key Generator
Generate strong random AES keys (256, 192 or 128 bits) in hex, Base64 or JWK, with a matching IV — created in your browser.
● 🔒 Your data is processed locally in your browser with the Web Crypto API and is never uploaded to our servers.
How to generate an AES key
- Choose the key size: 256 bits is recommended.
- Choose the format your code or configuration expects: hex, Base64, Base64URL or JWK (JSON Web Key).
- Choose the IV (initialization vector) size for your mode: 12 bytes for AES-GCM, 16 bytes for AES-CBC or CTR.
- Click Generate new key and copy the key and the IV.
The key is produced by your browser's Web Crypto API (crypto.subtle.generateKey), which uses your operating system's cryptographic random generator. It is never sent to a server.
AES key sizes and lengths
| Key | Bytes | Hex characters | Base64 characters | Base64URL |
|---|---|---|---|---|
| AES-128 | 16 | 32 | 24 | 22 |
| AES-192 | 24 | 48 | 32 | 32 |
| AES-256 | 32 | 64 | 44 | 43 |
So an AES-256 key is 32 bytes: 64 characters in hex or 44 in Base64. If a library asks for a “32-character key”, it usually means 32 bytes, not a 32-character password. All three sizes are secure; AES-256 adds a margin for long-term data and is the common default.
Generate an AES key in code
| Tool | 256-bit key |
|---|---|
| OpenSSL (Linux, macOS) | openssl rand -hex 32 or openssl rand -base64 32 |
| Linux shell | head -c 32 /dev/urandom | base64 |
| Python | secrets.token_bytes(32) or secrets.token_hex(32) |
| Node.js | crypto.randomBytes(32).toString("hex") |
| Java | KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(256); |
| C# | using var aes = Aes.Create(); aes.KeySize = 256; aes.GenerateKey(); |
Keys and IVs: the rules
- Never reuse an IV with the same key, especially with AES-GCM: generate a new random IV for every message and store it next to the ciphertext (it isn't secret).
- A password is not a key. To encrypt with a password, derive the key with PBKDF2, scrypt or Argon2 and a random salt — as the AES Encrypt tool does.
- Store keys like passwords: in a secrets manager or an environment variable, never in source code or a public repository.
- Rotate keys if they may have been exposed, and keep old keys only as long as you need to decrypt old data.
FAQ
Is it safe to generate an AES key online?
Here, yes: the key is generated in your browser with the operating system's secure random generator, and it never leaves your device. For production secrets, you can also run one of the commands above on your server.
Which format should I choose?
Hex is the easiest to read and paste in config files; Base64 is shorter; Base64URL is safe in URLs and JSON; JWK is the format of the Web Crypto API and JOSE libraries.
Can I test the key right away?
Yes: use it with AES-GCM Encrypt, then decrypt with AES-GCM Decrypt.
Is AES-128 still secure?
Yes. No practical attack breaks AES-128; AES-256 is chosen for an extra margin (for example against future quantum computers) and because many standards require it.
I need random bytes for something else.
Use the Random Bytes Generator or the Secure Token Generator for API tokens.