3v4l.org

run code in 300+ PHP versions simultaneously
<?php function csidAES($strMessage, $strKey, $strOperation = 'encrypt') { /** * csidAES * Provides encryption (default) and decryption suitable for use with the CSID SMS API. * @license CSID Partner Restricted * @param string $strMessage The message (cleartext or cyphertext) on which to operate. * @param string $strKey The agreed-upon encryption key. * @param string $strOperation OPTIONAL: One of 'encrypt' or 'decrypt' (default: * 'encrypt'). * @return string|bool Returns the resulting text, or FALSE on failure. */ echo $strMessage . ' is input to : ' . $strOperation . "<br/>"; switch ($strOperation){ case 'encrypt': echo "md5 of '".$strMessage . "' is : " . md5($strMessage) . "<br/>"; $AES_KEY = substr(md5($strKey), 0, 16); $iv = mcrypt_create_iv(16, MCRYPT_RAND); echo $iv . " - random generated IV<br/>"; //Perform encryption $ctext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $strMessage, MCRYPT_MODE_CBC, $iv); echo $ctext . " - encrypted<br/>"; $ctext = $iv.$ctext; echo $ctext . " - iv.ctext<br/>"; // Base64-encode, then urlencode the ciphertext $ctext = urlencode(base64_encode($ctext)); echo $ctext . " - url encoded ctext<br/>"; return $ctext; break; case 'decrypt': $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); echo $key_size . " - key_size<br/>"; $AES_KEY = substr(md5($strKey), 0, 16); echo $AES_KEY . " - AES_KEY<br/>"; $iv = mcrypt_create_iv(16, MCRYPT_RAND); echo $iv . " - random generated IV<br/>"; //Perform a base64_decode. $ctext = base64_decode($strMessage); echo $ctext . " - decoded input<br/>"; $thIV = substr($ctext,0,16); echo "thIV : " . $thIV . "<br/>"; $thingForDecoding = substr($ctext,16); echo "thingForDecoding : " . $thingForDecoding . "<br/>"; //NOTE: No need to urldecode; the API server did it for us. //Perform decryption $ptext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $ctext, MCRYPT_MODE_CBC, $iv); echo $ptext . " - decrypted<br/>"; $ptext = substr($ptext,16); echo $ptext . " - a substring of it"; $final = str_replace(chr(0),"",$ptext); echo $final . " - final"; return $final;//str_replace(chr(0),"",$ptext); break; default: return false; break; } } $csIDn = new ReflectionFunction('csidAES'); $originalText = 'Mirko Atanasov'; $encrypted = $csIDn->invoke($originalText , 'g3rWsiNm7Gwh9qMc','encrypt'); echo $encrypted; echo "<br/><br/> and now the decryption<br/><br/>"; $decrypted = $csIDn->invoke($encrypted, 'g3rWsiNm7Gwh9qMc','decrypt'); echo $decrypted; ?>
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 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
Mirko Atanasov is input to : encrypt<br/>md5 of 'Mirko Atanasov' is : 429d6d7e5cd4b233dcb12a1fa9a05d45<br/> Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/3DPMt:19 Stack trace: #0 [internal function]: csidAES('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt') #1 /in/3DPMt(68): ReflectionFunction->invoke('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt') #2 {main} thrown in /in/3DPMt on line 19
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 Mirko Atanasov is input to : encrypt<br/>md5 of 'Mirko Atanasov' is : 429d6d7e5cd4b233dcb12a1fa9a05d45<br/> Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/3DPMt:19 Stack trace: #0 [internal function]: csidAES('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt') #1 /in/3DPMt(68): ReflectionFunction->invoke('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt') #2 {main} thrown in /in/3DPMt on line 19
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Mirko Atanasov is input to : encrypt<br/>md5 of 'Mirko Atanasov' is : 429d6d7e5cd4b233dcb12a1fa9a05d45<br/> Fatal error: Call to undefined function mcrypt_create_iv() in /in/3DPMt on line 19
Process exited with code 255.

preferences:
206.31 ms | 402 KiB | 327 Q