3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $config = array( "digest_alg" => "sha1", "private_key_bits" => 1024, "private_key_type" => OPENSSL_KEYTYPE_RSA, ); // Create the private and public key $res = openssl_pkey_new($config); $output = ''; // Create the keypair //$res=openssl_pkey_new(); // Get private key openssl_pkey_export($res, $privatekey); $privatekey_string=base64_encode($privatekey); // Get public key $publickey=openssl_pkey_get_details($res); $publickey_string=base64_encode($publickey["key"]); echo "Private Key:<BR>$privatekey_string<br><br>Public Key:<BR>$publickey_string<BR><BR>"; $chunk="HelloWorld!"; openssl_private_encrypt($chunk, $encrypted, $privatekey,$padding = OPENSSL_NO_PADDING); $encrypted_string= base64_encode($encrypted); echo "Encrypted:<BR>$encrypted_string<br>";
based on PDSFE
Output for 7.2.0 - 7.3.1
Warning: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' (this will throw an Error in a future version of PHP) in /in/HNd9j on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/HNd9j:9 Stack trace: #0 {main} thrown in /in/HNd9j on line 9
Process exited with code 255.
Output for 7.0.0 - 7.1.25
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/HNd9j on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/HNd9j:9 Stack trace: #0 {main} thrown in /in/HNd9j on line 9
Process exited with code 255.
Output for hhvm-3.22.0
Warning: cannot get key from parameter 1 in /in/HNd9j on line -1 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/HNd9j on line -1 Private Key:<BR><br><br>Public Key:<BR><BR><BR> Warning: key param is not a valid private key in /in/HNd9j on line -1 Encrypted:<BR><br>
Output for hhvm-3.20.2 - 3.21.3
Warning: cannot get key from parameter 1 in /in/HNd9j on line 16 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/HNd9j on line 19 Private Key:<BR><br><br>Public Key:<BR><BR><BR> Warning: key param is not a valid private key in /in/HNd9j on line 24 Encrypted:<BR><br>
Output for hhvm-3.18.4 - 3.19.2
Warning: cannot get key from parameter 1 in /in/HNd9j on line 16 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 17 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/HNd9j on line 19 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 20 Private Key:<BR><br><br>Public Key:<BR><BR><BR> Warning: key param is not a valid private key in /in/HNd9j on line 24 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 26 Encrypted:<BR><br>
Output for hhvm-3.11.1 - 3.17.3
Warning: cannot get key from parameter 1 in /in/HNd9j on line 16 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 17 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, null given in /in/HNd9j on line 19 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 20 Private Key:<BR><br><br>Public Key:<BR><BR><BR> Warning: key param is not a valid private key in /in/HNd9j on line 24 Warning: base64_encode() expects parameter 1 to be string, null given in /in/HNd9j on line 26 Encrypted:<BR><br>
Output for hhvm-3.10.1
Warning: cannot get key from parameter 1 in /in/HNd9j on line 16 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, null given in /in/HNd9j on line 19 Private Key:<BR><br><br>Public Key:<BR><BR><BR> Warning: key param is not a valid private key in /in/HNd9j on line 24 Encrypted:<BR><br>
Output for 5.3.18 - 5.6.38
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/HNd9j on line 5 Fatal error: Call to undefined function openssl_pkey_new() in /in/HNd9j on line 9
Process exited with code 255.