rc4-40 encrypt & decrypt online
LegacyEncrypt or decrypt text with rc4-40 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 · 9 bytes 9 from your secret
- 6d7920736563726574
6d7920736563726574 - IV
- not used by this mode
- Text in UTF-8 11 bytes, no padding needed
- 68656c6c6f20776f726c64
- Encrypted · 11 bytes
- 02c0cef43baf5c5e0a4ce2
02c0cef43baf5c5e0a4ce2 - As Base64 what the tool shows
AsDO9DuvXF4KTOI=
from your inputzero bytesciphertext
What is rc4-40?
RC4 is a stream cipher by Ron Rivest (1987), once used in SSL, TLS and WEP. Its keystream has measurable biases, and TLS has banned it since 2015 (RFC 7465). This variant uses a 40-bit key, the old export grade that can be brute-forced quickly. As a stream cipher, it XORs a keystream with the text, so the output is as long as the input.
How your secret becomes the key
The default key length is 5 bytes (40 bits). Shorter secrets are padded with zero bytes to 5 bytes. Longer secrets are used in full, because RC4 accepts variable key lengths.
- WEP and WPA-TKIP Wi-Fi (both broken)
- Old SSL/TLS, PDF and Microsoft Office 97–2003 encryption
Is it safe to use?
RC4. Can be attacked in practice. Only use it to read or match old data.
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 RC4 encrypts
A stream cipher makes a long pseudo-random keystream from the key (and a nonce) and XORs it with the text. There are no blocks and no padding: the output has exactly as many bytes as the input.
The same key and nonce always give the same keystream. This tool uses no nonce, so two texts encrypted with the same secret can be XORed against each other to cancel the keystream. Never reuse a key and nonce for real data.
The same result in your code
Every snippet prints AsDO9DuvXF4KTOI= 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("6d7920736563726574"); // "my secret" as UTF-8 bytes echo openssl_encrypt("hello world", "rc4-40", $key, 0);
Shortest form, same result: openssl_encrypt("hello world", "rc4-40", "my secret"). PHP pads the secret itself but warns about the empty IV. On OpenSSL 3, PHP needs the legacy provider enabled in openssl.cnf.
import { createCipheriv } from 'node:crypto'; const key = Buffer.from("6d7920736563726574", 'hex'); // "my secret" as UTF-8 bytes const c = createCipheriv("rc4-40", key, null); console.log(Buffer.concat([c.update("hello world", 'utf8'), c.final()]).toString('base64'));
Run with node --openssl-legacy-provider: OpenSSL 3 hides this cipher by default.
package main import ( "crypto/rc4" "encoding/base64" "encoding/hex" "fmt" ) func main() { key, _ := hex.DecodeString("6d7920736563726574") // "my secret" as UTF-8 bytes c, _ := rc4.NewCipher(key) data := []byte("hello world") out := make([]byte, len(data)) c.XORKeyStream(out, data) fmt.Println(base64.StdEncoding.EncodeToString(out)) }
Why your rc4-40 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.
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.
This mode needs no padding: 11 bytes in, 11 bytes out. If your library adds PKCS#7 padding or expects whole blocks, it is configured for CBC or ECB.
Without a nonce, every text encrypted with the same secret uses the same keystream. XOR two ciphertexts and the keystream cancels out, leaving the XOR of the two texts. That's how WEP was broken.
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.
OpenSSL 3 moved this cipher to the legacy provider. Node.js, PHP, Python and the openssl command line built on OpenSSL 3 report it as unsupported until the legacy provider is loaded (node --openssl-legacy-provider, openssl enc -provider legacy -provider default).
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.
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 rc4-40.
Every RC2, RC4 and RC5 variant, same input
The text The quick brown fox jumps over the lazy dog (43 bytes) with the secret my secret in all 18 RC2, RC4 and RC5 ciphers. The last column lists names that give the same result: aliases, and modes that agree for this input. Type a text and a secret in the tool above to use yours.
| Cipher | Result (Base64) | Same as |
|---|---|---|
| rc5 | b0Y75AkCYLUjsca/h8U/zTxswBXuXVVjTtwSzRpjQYzWOrTgZm3mOaxPrZBurSxl | rc5-cbc |
| rc2 Legacy | p23M7j59Qn+e1KoNAtgQuW4OBtsGuOZx99mLhg3ckwivFbqatlDn7SYam7SSluSg | rc2-128, rc2-cbc |
| rc2-128 Legacy | p23M7j59Qn+e1KoNAtgQuW4OBtsGuOZx99mLhg3ckwivFbqatlDn7SYam7SSluSg | rc2, rc2-cbc |
| rc2-40 Legacy | xpPU2XVvYsOWGdtT6IaI3fYxuvi1k8hE491FiEJ4cqPDOyji2rZm/KW0TP23a40z | rc2-40-cbc |
| rc2-40-cbc Legacy | xpPU2XVvYsOWGdtT6IaI3fYxuvi1k8hE491FiEJ4cqPDOyji2rZm/KW0TP23a40z | rc2-40 |
| rc2-64 Legacy | GMH0GJjoTKzKdw6yko5HNRNwQ6xpc7CU0FNw6wThsIJsOhDijjkY2GMDNvAhZtEw | rc2-64-cbc |
| rc2-64-cbc Legacy | GMH0GJjoTKzKdw6yko5HNRNwQ6xpc7CU0FNw6wThsIJsOhDijjkY2GMDNvAhZtEw | rc2-64 |
| rc2-cbc Legacy | p23M7j59Qn+e1KoNAtgQuW4OBtsGuOZx99mLhg3ckwivFbqatlDn7SYam7SSluSg | rc2, rc2-128 |
| rc2-cfb Legacy | kDTW1hVWIKr2JKort9g+HR6Jl/urjTOwG/2HTwCUzAT2kJ2Ufwx+4lSFNw== | |
| rc2-ecb Legacy | p23M7j59Qn9hqu/aNa4p90oI8UaToXowTAdiZl+efrgBCO9kl2Za/+GtD4rwQQzU | |
| rc2-ofb Legacy | kDTW1hVWIKqH2XLBBcPCfXQC9t/2wl9ZZXRcG3xuLCUEahe8qL3eoeBeig== | |
| rc4 Legacy | Kx7g6UroSjBDWBIi8m/39cMAeJrjapwioV/VB4OQyQyJ2H9EJIktBznZ8Q== | rc4-hmac-md5 |
| rc4-40 Legacy | Ps3HuCX6QlITAORUiXB5cMUNzAD5MWLUtcuA+RNMSOlFscgZPN56KMMTAQ== | |
| rc4-hmac-md5 Legacy | Kx7g6UroSjBDWBIi8m/39cMAeJrjapwioV/VB4OQyQyJ2H9EJIktBznZ8Q== | rc4 |
| rc5-cbc | b0Y75AkCYLUjsca/h8U/zTxswBXuXVVjTtwSzRpjQYzWOrTgZm3mOaxPrZBurSxl | rc5 |
| rc5-cfb | rSJjpziyD1WhV34ys+834YzpfKE+2XH1nkDaBoMtD0JnkOE2cKtfIeLdlA== | |
| rc5-ecb Legacy | b0Y75AkCYLWBXdDbTOwK+Ks902etwmkO0mQ2CmBnbgpaKoZu1nwJfU8zPhzp+vII | |
| rc5-ofb | rSJjpziyD1U6G8uysBbPI54nNg61sQQ0scizwxesez0Gu7ZcLFk8qI5iqQ== |
rc4-40 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 | rc4-40 (Base64) |
|---|---|
| empty string | |
a | Cw== |
hello world | AsDO9DuvXF4KTOI= |
0123456789abcdef | WpSQq2C6HQZAGedEhWNyNg== |
The quick brown fox jumps over the lazy dog | Ps3HuCX6QlITAORUiXB5cMUNzAD5MWLUtcuA+RNMSOlFscgZPN56KMMTAQ== |
Questions about rc4-40
Can rc4-40 be decrypted without the secret?
No. Without the secret there is no shortcut, except that RC4's weak key lets a determined attacker try every key. A short or common secret can be guessed, though, because the tool uses it directly as the key.
Why does my rc4-40 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 is the rc4-40 output shorter than with CBC?
RC4-40 needs no padding: the ciphertext has exactly as many bytes as the text, while CBC rounds up to whole blocks.
Is RC4 secure?
No. RC4 can be attacked in practice. Use it only to read or match old data.
How long should my secret be?
At least 5 bytes, the default key length; longer secrets are used in full. For real security a random key is better than a typed word.