3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Set the method $method = 'AES-128-CBC'; // Set the encryption key $encryption_key = 'myencryptionkey'; // Generet a random initialisation vector $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)); // Define the date to be encrypted $data = "Encrypt me, please!"; var_dump("Before encryption: $data"); // Encrypt the data $encrypted = openssl_encrypt($data, $method, $encryption_key, 0, $iv); var_dump("Encrypted: ${encrypted}"); // Append the vector at the end of the encrypted string $encrypted = $encrypted . ':' . $iv; var_dump($encrypted); // Explode the string using the `:` separator. $parts = explode(':', $encrypted); // Decrypt the data $decrypted = openssl_decrypt($parts[0], $method, $encryption_key, 0, $parts[1]); var_dump("Decrypted: ${decrypted}");
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/ookl5 on line 21 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/ookl5 on line 33 Fatal error: Uncaught Error: Call to undefined function openssl_random_pseudo_bytes() in /in/ookl5:11 Stack trace: #0 {main} thrown in /in/ookl5 on line 11
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/ookl5 on line 21 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/ookl5 on line 33 Fatal error: Uncaught Error: Call to undefined function openssl_random_pseudo_bytes() in /in/ookl5:11 Stack trace: #0 {main} thrown in /in/ookl5 on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: Call to undefined function openssl_random_pseudo_bytes() in /in/ookl5:11 Stack trace: #0 {main} thrown in /in/ookl5 on line 11
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/ookl5 on line 11
Process exited with code 255.

preferences:
297.25 ms | 402 KiB | 339 Q