3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** Name: PHP Encryption: Desc: Encrypt and Decrypt data. Version: V1.0 Date: 3/11/2017 Author: Prince Adeyemi Contact: prince@vegasnewspaper.com Facebook: fb.com/YourVegasPrince */ // Encryption setup: $dataToEncrypt = "My Secret Telegram: Hakuna matata!"; $encryptMethod = "AES-256-CBC"; $mySecretHash = "somethingRandom12!)!)I!@1U2 goes gere"; //$iv = mcrypt_create_iv(16, MCRYPT_RAND); // php versopm 5.6.0- 7.2.x compability; If( phpversion() >= 7) { $bytes = random_bytes(8); $iv = (bin2hex($bytes)); } elseif( phpversion() < 7 ) { for ($i = -1; $i <= 16; $i++) { $iv = openssl_random_pseudo_bytes($i, $cstrong); } } else { $iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); } //Encrypt data: $encryptedData = openssl_encrypt($dataToEncrypt,$encryptMethod,$mySecretHash, 0, $iv); //Decrypt data: $decryptedData = openssl_decrypt($encryptedData, $encryptMethod, $mySecretHash, 0, $iv); //OUTPUT: echo ("RandomIV : " . $iv . "\n"); echo ( "Secret message : " . $dataToEncrypt ."\n" ); echo ( "Encrypted message : ". $encryptedData ."\n" ); echo ( "Decrypted message: ". $decryptedData ."\n"); ?>
based on SNiQD
Output for 7.1.0 - 7.2.1
Fatal error: Uncaught Error: Call to undefined function openssl_encrypt() in /in/bB0dV:37 Stack trace: #0 {main} thrown in /in/bB0dV on line 37
Process exited with code 255.
Output for hhvm-3.22.0
RandomIV : ff83b742b2f888c4 Secret message : My Secret Telegram: Hakuna matata! Encrypted message : mniYgJSesAD7vUihXkQWf7LbO3GAE6uXTA858ruIklL8RYP+JQ0sy6ObRB+U5/ec Decrypted message: My Secret Telegram: Hakuna matata!
Output for hhvm-3.21.3
RandomIV : 73ae2fe621eb238c Secret message : My Secret Telegram: Hakuna matata! Encrypted message : b+Feg6PZjPr3NHf6TdaWnSbFlbsZ5CwBax1PE0KzXVz4FZ5tu3Hw9qYUAqymw/py Decrypted message: My Secret Telegram: Hakuna matata!
Output for hhvm-3.18.5
RandomIV : 8bf724d19138f052 Secret message : My Secret Telegram: Hakuna matata! Encrypted message : hIdkPr8I/EbMh6K5k6YoHdn3jg8aNCOp3ilP8VQzS+/JSwfXhHsDs7tY9vWHRtSq Decrypted message: My Secret Telegram: Hakuna matata!