3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function decryptData($value){ $key = "ICS2015"; $crypttext = base64_decode($value); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv); return trim($decrypttext); } function encryptData($value) { $key = "ICS2015"; $text = $value; // getting the size of the IV (Initialization Vector) belonging to a specific cipher / mode combination // Accept two params // 1: cipher (MCPYPT_ciphername constraint or the name of algorithms string) // 2: mode (MCPYPT_MODE_modename constraint or one of the following string - ecb, cbc, cfb, ofb, nofb or stream ) $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); // Create an initialization vector(IV) from RANDOM source $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); // Encrypt plaintext with given params $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); return base64_encode($crypttext); } $data = 'testdata'; $encData = encryptData($data); $decData = decryptData($encData); echo "$data : " + $data + "\r\n"; echo "$encData : " + $encData + "\r\n"; echo "$decData : " + $decData + "\r\n"; ?>
based on AZM5H
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/UnUjb:22 Stack trace: #0 /in/UnUjb(33): encryptData('testdata') #1 {main} thrown in /in/UnUjb on line 22
Process exited with code 255.
Output for 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Warning: mcrypt_encrypt(): Key of size 7 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in /in/UnUjb on line 27 Warning: mcrypt_decrypt(): Key of size 7 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in /in/UnUjb on line 10 000
Output for 5.3.20 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/UnUjb on line 22
Process exited with code 255.
Output for 5.4.10 - 5.5.34
000