3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function encrypt_decrypt($action, $string) { $output = false; $encrypt_method = "MCRYPT_MODE_CBC,"; $secret_key = 'This is my secret key'; $secret_iv = 'This is my secret iv'; // 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); if( $action == 'encrypt' ) { $output = mcrypt_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if( $action == 'decrypt' ){ $output = mcrypt_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } $plain_txt = "This is my plain text"; echo "Plain Text = $plain_txt\n"; $encrypted_txt = encrypt_decrypt('encrypt', $plain_txt); echo "Encrypted Text = $encrypted_txt\n"; $decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt); echo "Decrypted Text = $decrypted_txt\n"; if( $plain_txt === $decrypted_txt ) echo "SUCCESS"; else echo "FAILED"; echo "\n";
based on CArS9
Output for 7.0.6 - 7.2.0
Plain Text = This is my plain text Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() in /in/k1VeV:17 Stack trace: #0 /in/k1VeV(30): encrypt_decrypt('encrypt', 'This is my plai...') #1 {main} thrown in /in/k1VeV on line 17
Process exited with code 255.
Output for 5.4.1 - 5.5.34, 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Plain Text = This is my plain text Warning: mcrypt_encrypt(): Module initialization failed in /in/k1VeV on line 17 Encrypted Text = Warning: mcrypt_decrypt(): Module initialization failed in /in/k1VeV on line 21 Decrypted Text = FAILED
Output for 5.3.18 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Plain Text = This is my plain text Fatal error: Call to undefined function mcrypt_encrypt() in /in/k1VeV on line 17
Process exited with code 255.