3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encrypt_decrypt($action, $string, $secret_key, $secret_iv) { $output = false; if (!extension_loaded('openssl')) { return $string; } $encrypt_method = "AES-256-CBC"; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); echo $key; echo $iv; if($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if($action == 'decrypt'){ $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } echo encrypt_decrypt('decrypt', 'NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=', ENCRYPTION_KEY, ENCRYPTION_VI);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Undefined constant "ENCRYPTION_KEY" in /in/9ihf9:28 Stack trace: #0 {main} thrown in /in/9ihf9 on line 28
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 Fatal error: Uncaught Error: Undefined constant "ENCRYPTION_KEY" in /in/9ihf9:28 Stack trace: #0 {main} thrown in /in/9ihf9 on line 28
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' (this will throw an Error in a future version of PHP) in /in/9ihf9 on line 28 Warning: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' (this will throw an Error in a future version of PHP) in /in/9ihf9 on line 28 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' in /in/9ihf9 on line 28 Notice: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' in /in/9ihf9 on line 28 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=

preferences:
195.68 ms | 402 KiB | 288 Q