3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $config = array( "digest_alg" => "sha512", "private_key_bits" => 512, "private_key_type" => OPENSSL_KEYTYPE_RSA, ); // Create the private and public key $res = openssl_pkey_new($config); // Extract the private key from $res to $privKey openssl_pkey_export($res, $privKey); // Extract the public key from $res to $pubKey $pubKey = openssl_pkey_get_details($res); $pubKey = $pubKey["key"]; $data = 'plaintext data goes here'; // Encrypt the data to $encrypted using the public key openssl_public_encrypt($data, $encrypted, $pubKey); // Decrypt the data using the private key and store the results in $decrypted openssl_private_decrypt($encrypted, $decrypted, $privKey); echo $decrypted;
based on ll446
Output for 7.0.20, 7.1.5 - 7.2.0
Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/VMLuf on line 12 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/VMLuf on line 15 Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/VMLuf on line 21 Warning: openssl_private_decrypt(): key parameter is not a valid private key in /in/VMLuf on line 24
Output for 5.4.15 - 7.0.6, 7.1.0
plaintext data goes here
Output for 5.3.19 - 5.4.14
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/VMLuf on line 5 Fatal error: Call to undefined function openssl_pkey_new() in /in/VMLuf on line 9
Process exited with code 255.