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 . "->" . $encryptedviaprivatekey; echo "\n\n";
based on IubjM

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
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/3TGkU on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/3TGkU:9 Stack trace: #0 {main} thrown in /in/3TGkU on line 9
Output for Arrow functions
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/3TGkU on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/3TGkU:9 Stack trace: #0 {main} thrown in /in/3TGkU on line 9
Output for Object typehint
Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/3TGkU on line 16 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/3TGkU on line 19 Private Key: <br><br>Public Key:<BR> Warning: openssl_private_encrypt(): key param is not a valid private key in /in/3TGkU on line 26 HelloWorld!->
Output for Array change keys
Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/3TGkU on line 16 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/3TGkU on line 19 Private Key: <br><br>Public Key:<BR> Warning: openssl_private_encrypt(): key param is not a valid private key in /in/3TGkU on line 26 HelloWorld!->
Output for Lexical anon
Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/3TGkU on line 16 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/3TGkU on line 19 Private Key: <br><br>Public Key:<BR> Warning: openssl_private_encrypt(): key param is not a valid private key in /in/3TGkU on line 26 HelloWorld!->

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page