aes128 encrypt & decrypt online
Encrypt or decrypt text with aes128 and a secret. Same result as PHP's openssl_encrypt, and nothing leaves your browser.
The bytes behind your result
Your code gives a different result? Almost always the key or the IV differ. Here you see exactly which bytes the tool used for the secret and text in the tool above: copy the key and IV in hex into your own code. Shown for the text hello world and the secret my secret until you type above.
- Key · 16 bytes 9 from your secret, 7 zero bytes added
- 6d792073656372657400000000000000
6d792073656372657400000000000000 - IV · 16 bytes none given, so zero bytes
- 00000000000000000000000000000000
00000000000000000000000000000000 - Text in UTF-8 11 bytes of text + 5 bytes PKCS#7 padding (value
05) = 16 bytes, 1 block of 16 - 68656c6c6f20776f726c640505050505
- Encrypted · 16 bytes
- 6ee6bd637c5c769bd83e6e3ee0f104f5
6ee6bd637c5c769bd83e6e3ee0f104f5 - As Base64 what the tool shows
bua9Y3xcdpvYPm4+4PEE9Q==
from your inputzero bytespaddingciphertext
What is aes128?
aes128 is the short name OpenSSL and PHP use for AES-128-CBC: AES with a 128-bit key in CBC mode. It gives exactly the same result as aes-128-cbc. AES is the block cipher NIST standardised in 2001 (FIPS 197), originally called Rijndael. It is the most widely used cipher today and has no practical attack. It uses a 128-bit key (10 rounds) in Cipher Block Chaining mode: each 16-byte block is mixed with the previous encrypted block before it is encrypted.
How your secret becomes the key
AES-128-CBC needs exactly 16 bytes (128 bits) of key. The tool takes your secret as UTF-8 bytes and pads it with zero bytes to 16 bytes, or cuts it after 16 bytes.
- HTTPS and TLS
- Wi-Fi (WPA2, WPA3)
- Disk encryption: BitLocker, FileVault, LUKS
- VPNs, ZIP and 7-Zip archives, password managers
Is it safe to use?
AES. No practical attack on the cipher itself is known.
The setup of this tool is made for compatibility with PHP's openssl_encrypt, not for protecting secrets: the IV is always zero, the secret is used as the key without a key derivation function, and nothing detects changes to the ciphertext.
For real secrets use an authenticated mode such as AES-256-GCM or ChaCha20-Poly1305 with a fresh random nonce for every message, and derive the key from a password with Argon2id, scrypt or PBKDF2. What is a key derivation function?
How CBC mode works
CBC splits the text into 16-byte blocks. Before a block is encrypted, it is XORed with the previous encrypted block; the first block is XORed with the IV. So every block depends on all blocks before it.
The last block is filled up with PKCS#7 padding: if 5 bytes are missing, five bytes 05 are added. A text that fills its last block exactly gets a whole extra block of padding. That is why the output is always a multiple of 16 bytes and at least one byte longer than the input.
With a random IV, the same text gives a different result each time. This tool uses no IV (zero bytes), so the same text and secret always give the same result, and the first block is identical to ECB.
Really calculated: each square is one 16-byte block, coloured by the first byte of its ciphertext. With ECB, equal blocks stay equal and the heart shows through. With CBC, every block depends on the one before.
The same result in your code
Every snippet prints bua9Y3xcdpvYPm4+4PEE9Q== for the text hello world and the secret my secret, the same as the tool. The key and IV are written out in hex, so you can see what the tool does with the secret. Your own key and IV are in What the tool did. All snippets are run against PHP before each release.
$key = hex2bin("6d792073656372657400000000000000"); // "my secret" padded with zero bytes to 16 bytes $iv = hex2bin("00000000000000000000000000000000"); // no IV given: 16 zero bytes echo openssl_encrypt("hello world", "aes128", $key, 0, $iv);
Shortest form, same result: openssl_encrypt("hello world", "aes128", "my secret"). PHP pads the secret itself but warns about the empty IV.
# pip install cryptography import base64 from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding key = bytes.fromhex("6d792073656372657400000000000000") # "my secret" padded with zero bytes to 16 bytes iv = bytes(16) # no IV given: 16 zero bytes data = "hello world".encode() padder = padding.PKCS7(128).padder() data = padder.update(data) + padder.finalize() enc = Cipher(algorithms.AES(key), modes.CBC(iv)).encryptor() print(base64.b64encode(enc.update(data) + enc.finalize()).decode())
Python has no AES in the standard library; cryptography is the common package for it.
import { createCipheriv } from 'node:crypto'; const key = Buffer.from("6d792073656372657400000000000000", 'hex'); // "my secret" padded with zero bytes to 16 bytes const iv = Buffer.alloc(16); // no IV given: 16 zero bytes const c = createCipheriv("aes-128-cbc", key, iv); console.log(Buffer.concat([c.update("hello world", 'utf8'), c.final()]).toString('base64'));
import javax.crypto.Cipher; import javax.crypto.spec.*; import java.util.Base64; import java.util.HexFormat; public class Encrypt { public static void main(String[] args) throws Exception { byte[] key = HexFormat.of().parseHex("6d792073656372657400000000000000"); // "my secret" padded with zero bytes to 16 bytes byte[] iv = new byte[16]; // no IV given: 16 zero bytes Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv)); System.out.println(Base64.getEncoder().encodeToString(c.doFinal("hello world".getBytes("UTF-8")))); } }
Java 17 or newer (HexFormat). Java's PKCS5Padding is the same as PKCS#7.
package main import ( "bytes" "crypto/aes" "crypto/cipher" "encoding/base64" "encoding/hex" "fmt" ) func main() { key, _ := hex.DecodeString("6d792073656372657400000000000000") // "my secret" padded with zero bytes to 16 bytes block, _ := aes.NewCipher(key) iv := make([]byte, block.BlockSize()) // no IV given: zero bytes data := []byte("hello world") n := block.BlockSize() - len(data)%block.BlockSize() // PKCS#7 padding data = append(data, bytes.Repeat([]byte{byte(n)}, n)...) out := make([]byte, len(data)) cipher.NewCBCEncrypter(block, iv).CryptBlocks(out, data) fmt.Println(base64.StdEncoding.EncodeToString(out)) }
printf '%s' 'hello world' | openssl enc -aes-128-cbc -K 6d792073656372657400000000000000 -iv 00000000000000000000000000000000 -a -A
printf instead of echo: echo adds a line break, which changes the result. -K and -iv take hex; with -k or -pass, openssl derives a different key from a password.
Why your aes128 result doesn't match
Many tutorials turn a password into a key with SHA-256 or MD5. This tool doesn't: it uses the bytes of your secret directly and pads them with zero bytes. Copy the key in hex from What the tool did and use it as the raw key.
With a random IV the result changes every time. The tool uses no IV, which in PHP means zero bytes. Use a zero IV of the right length to get the same result, and keep the random IV for real data.
The tool shows the raw ciphertext bytes as Base64. Many libraries return hex or raw bytes. Convert before comparing, or compare with the hex blocks in What the tool did.
The tool pads with PKCS#7 (OpenSSL's default). Some libraries pad with zeros or not at all. A text of exactly one block still gets a full block of padding (10 10 … 10 for 16-byte blocks).
With a zero IV, the first CBC block is exactly the ECB block, because XOR with zeros changes nothing. Texts up to one block long (15 bytes plus padding) give the same result in CBC and ECB. From the second block on they differ, see the family comparison.
Like the old site, the tool trims spaces and line breaks at the start and end of the text and the secret, and sends line breaks as CRLF (\r\n), as a browser form does. echo "text" | in a shell adds a line break at the end.
Only the first bytes up to the key length count, the rest is cut off. Two secrets that start with the same bytes give the same result. Non-ASCII characters take 2–4 bytes in UTF-8, so they fill the key faster.
Given a password, the openssl command line derives key and IV from it with a random salt (EVP_BytesToKey or PBKDF2), and the output starts with U2FsdGVkX1 ("Salted__"). That is a different format. Pass the key and IV in hex with -K and -iv instead, as in the code example.
CryptoJS.AES.encrypt(text, "password") treats a string as a passphrase and uses the same salted OpenSSL format (U2FsdGVkX1…). To match this tool, pass the key and IV as WordArrays with CryptoJS.enc.Hex.parse().
Encrypted something here years ago?
Paste the Base64 result and the secret. Your browser tries all 174 ciphers of this site and shows those that give readable text. Useful if you don't remember the cipher, or to check whether your ciphertext really is aes128.
Every AES-128 variant, same input
The text The quick brown fox jumps over the lazy dog (43 bytes) with the secret my secret in all 19 AES-128 ciphers. The last column lists names that give the same result: aliases, and modes that agree for this input. Highlighted: the same start as aes128. Watch how CBC and ECB share the first block, and CFB, OFB and CTR the first 16 bytes. Type a text and a secret in the tool above to use yours.
| Cipher | Result (Base64) | Same as |
|---|---|---|
| aes-128-cbc | i7vfHATmvCrxYy9qiHaxyt3wvORh88GUuzSzf9bw5++CM0S6QDK4fE1yrHZ4FB16 | aes-128-cbc-hmac-sha1, aes-128-cbc-hmac-sha256, aes128 |
| aes-128-cbc-hmac-sha1 | i7vfHATmvCrxYy9qiHaxyt3wvORh88GUuzSzf9bw5++CM0S6QDK4fE1yrHZ4FB16 | aes-128-cbc, aes-128-cbc-hmac-sha256, aes128 |
| aes-128-cbc-hmac-sha256 | i7vfHATmvCrxYy9qiHaxyt3wvORh88GUuzSzf9bw5++CM0S6QDK4fE1yrHZ4FB16 | aes-128-cbc, aes-128-cbc-hmac-sha1, aes128 |
| aes-128-ccm | no result | |
| aes-128-cfb | SsMSzl/rFRhPJZExIDz+sUlfFDd/sM9mIwgYoe/OcKBoUd6F+Dn7koQ31w== | |
| aes-128-cfb1 | fF3w2g9a5AiBbI20o5ld5b0YUXRTx8a/xaZZESb8yORNHjq+jR5ZTOZj1Q== | |
| aes-128-cfb8 | ShS+jZYSdD3MJfBmnfEz+jKM7H9b57w11NF6NerxqRHJn7LTBwGSt6Cxjw== | |
| aes-128-ctr | SsMSzl/rFRhPJZExIDz+sfw/dZn9RqQLXEVED9wGFizt5fBWSuFBVf80sQ== | |
| aes-128-ecb Legacy | i7vfHATmvCrxYy9qiHaxytv2lacGBXo0DF+/4sBumgW7VIfdLGIsL9BqLKy3VkYU | |
| aes-128-gcm | no result | |
| aes-128-ocb | no result | |
| aes-128-ofb | SsMSzl/rFRhPJZExIDz+sQwGyExofWfDoTQanZtW4UmP030OhqzkHKJNzA== | |
| aes-128-xts | WTrZgUQlmoZxcG/d9PFwRD4r+M544ix/5U1usg5acNgHqnX6l7EW353Dxw== | |
| aes128 | i7vfHATmvCrxYy9qiHaxyt3wvORh88GUuzSzf9bw5++CM0S6QDK4fE1yrHZ4FB16 | aes-128-cbc, aes-128-cbc-hmac-sha1, aes-128-cbc-hmac-sha256 |
| aes128-wrap | no result | |
| id-aes128-ccm | no result | |
| id-aes128-gcm | no result | |
| id-aes128-wrap | no result | |
| id-aes128-wrap-pad | FNGT9AP/e0vOHlZxK9DxyRbU/psJmNNitheSgx9xaLyO9+uPJbw9DTr7yfX3Id+AtnjPISM2+Pw= |
aes128 test values
Results for common test strings with the secret my secret (UTF-8, no line break, zero IV), exactly as the tool and PHP's openssl_encrypt give them. Use them to check your own implementation.
| Text | aes128 (Base64) |
|---|---|
| empty string | zUzRVxRqmX8T9JkTKUOXgw== |
a | R//l4PmpkNGDflr3GraQrg== |
hello world | bua9Y3xcdpvYPm4+4PEE9Q== |
0123456789abcdef | sjbJH9CRV0ICo8xaHRJ7egWSmnC6eNvzu/Hm+bkdyhQ= |
The quick brown fox jumps over the lazy dog | i7vfHATmvCrxYy9qiHaxyt3wvORh88GUuzSzf9bw5++CM0S6QDK4fE1yrHZ4FB16 |
Questions about aes128
Is aes128 the same as aes-128-cbc?
Yes, in this tool and in PHP on OpenSSL 1.1.1 they give exactly the same result. aes128 is just another name, so you can decrypt with either.
Can aes128 be decrypted without the secret?
No. Without the secret there is no shortcut. A short or common secret can be guessed, though, because the tool uses it directly as the key.
Why does my aes128 code give a different result?
Almost always because of the key or the IV: the tool pads your secret with zero bytes instead of hashing it and uses a zero IV. Also check Base64 vs hex, padding, and spaces or line breaks the tool trims.
Why do aes-128-cbc and aes-128-ecb give the same result?
Only for short texts. With a zero IV, the first CBC block equals the ECB block. From the second block on, CBC mixes in the previous block and the results differ.
Is AES-128 secure?
AES-128 itself has no practical attack. AES-256 has a larger margin, but AES-128 is still considered secure. What makes a setup weak is a guessable key, a reused IV or missing authentication.
How long should my secret be?
Exactly 16 bytes (128 bits) fills the key; anything after that is ignored. For real security a random key is better than a typed word.