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:\n$privatekey_string<br><br>Public Key:<BR>$publickey_string\n\n"; $chunk="HelloWorld!"; //if(openssl_private_encrypt($chunk, $encrypted, $privatekey,$padding = OPENSSL_NO_PADDING)) openssl_private_encrypt($chunk, $encryptedviaprivatekey, $privatekey); echo $chunk . "->" . base64_encode($encryptedviaprivatekey); echo "\n\n";
based on 3TGkU
Output for 7.2.0 - 7.3.0
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/X2B53 on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/X2B53:9 Stack trace: #0 {main} thrown in /in/X2B53 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/X2B53 on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/X2B53:9 Stack trace: #0 {main} thrown in /in/X2B53 on line 9
Process exited with code 255.
Output for 5.3.18 - 5.6.38
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/X2B53 on line 5 Fatal error: Call to undefined function openssl_pkey_new() in /in/X2B53 on line 9
Process exited with code 255.