OpenSSL AES-256-CBC Encryption / Decryption
This tool runs 100% locally in your browser. Your key and data never leave your device. Even so, please test with sandbox keys, not production keys.
How it works
Payment integrations and other server-to-server APIs often exchange encrypted data with PHP's openssl_encrypt(). This tool works with one common way of writing it, so you can compare your code's output while integrating:
$iv = openssl_random_pseudo_bytes(16);
$encrypted = openssl_encrypt($payload, 'aes-256-cbc', $key, 0, $iv);
$result = base64_encode($encrypted . '::' . $iv);The result is layered. openssl_encrypt() with options set to 0 returns Base64 ciphertext. The code then appends :: and the 16 raw bytes of the IV, and Base64-encodes the whole thing again. To decrypt, the tool decodes the outer Base64, splits at the first ::, and uses the second part as the IV. The data is padded with PKCS#7.
The key needs the most care. $key is a plain string, used directly as the AES key without any key derivation. AES-256 needs exactly 32 bytes, so OpenSSL pads a shorter key with \0 bytes and ignores anything past 32 bytes. This tool does the same, and the hint under the key field shows how many bytes you entered. Because the key is measured in UTF-8 bytes, each Chinese character counts as three.
A new random IV is generated for every encryption, so encrypting the same text twice gives different output, and both decrypt correctly. This :: layout is a coding convention, not a standard, and CBC on its own does not detect tampering. Providers differ in key length, IV handling and encoding, so always check their technical documentation first.
To test your own output, enter the key, paste the result from your code and press Decrypt. If the original text comes back, your format matches. To go the other way, press Encrypt and have your code decrypt the result. Line breaks and spaces inside the Base64 are ignored, which helps with data copied from a log. Decrypted output is shown as UTF-8 text, so binary data will not display correctly. If decryption fails, check the key first, because a single wrong byte is enough to break it.
Result
Use cases
- Payment integration testing: Your server and a payment gateway exchange encrypted fields, and the other side reports that it cannot decrypt yours. Decrypt your output here with the test key to confirm whether your side is correct before going through the logs together.
- Debugging a failed decryption: openssl_decrypt() returns false and you cannot tell why. Paste the same data here. A format error points at the encoding or the :: layout, and a decryption error points at the key.
- Porting the format to another language: You are rewriting this PHP code in Node.js or Python and need sample data to test against. Encrypt something here, then make sure your new code can decrypt it, and the other way round.
FAQ
Q: Is my key or data uploaded?
A: No. Encryption and decryption run in your browser through the Web Crypto API, and nothing is sent to a server. Even so, use sandbox keys here. Production keys should not be pasted into any web page.
Q: How is this different from the AES-256-CBC tool on this site?
A: That tool takes a raw hexadecimal key and IV, and returns plain hexadecimal ciphertext. This one takes a text key, generates the IV for you, and uses the PHP base64 and :: format. Their output is not interchangeable.
Q: Why can't it decrypt my payment provider's data?
A: Providers differ. They may use a fixed IV, a hex key, a different key length, or another encoding, and some use AES-128 instead. This tool only handles the format shown on this page, so compare it with the provider's technical documentation first.
Q: Does it work with the openssl enc command?
A: Not directly. openssl enc with a password derives the key through a salted key derivation step and adds a Salted__ header, which is a different format. This tool matches the PHP openssl_encrypt() code shown above.
Q: Why is the output different each time?
A: Each encryption uses a new random IV, which is stored inside the result. Different output from the same text is expected, and every version decrypts with the same key.