3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $message = 'test'; $resource = openssl_pkey_new(['private_key_bits' => 512]); $public_key = openssl_pkey_get_details($resource)['key']; openssl_pkey_export($resource, $private_key); openssl_public_encrypt($message, $enc_message, $public_key); $enc_message = base64_encode($enc_message); openssl_private_decrypt($enc_message, $dec_message, $private_key); $dec_message = base64_decode($dec_message); echo '<pre>'; var_dump([ 'public_key' => $public_key, 'private_key' => $private_key, 'message' => $message, 'enc_message' => $enc_message, 'dec_message' => $dec_message ]); echo '</pre>';
based on b5CVb
Output for 7.1.20, 7.2.6 - 7.3.0beta1
Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/jRri9:4 Stack trace: #0 {main} thrown in /in/jRri9 on line 4
Process exited with code 255.
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.12, 7.2.0
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/jRri9 on line 5 Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/jRri9 on line 6 Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/jRri9 on line 8 Warning: openssl_private_decrypt(): key parameter is not a valid private key in /in/jRri9 on line 11 <pre>array(5) { ["public_key"]=> NULL ["private_key"]=> NULL ["message"]=> string(4) "test" ["enc_message"]=> string(0) "" ["dec_message"]=> string(0) "" } </pre>
Output for hhvm-3.22.0
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/jRri9 on line -1 Warning: cannot get key from parameter 1 in /in/jRri9 on line -1 Warning: key parameter is not a valid public key in /in/jRri9 on line -1 Warning: key parameter is not a valid private key in /in/jRri9 on line -1 <pre>array(5) { ["public_key"]=> NULL ["private_key"]=> NULL ["message"]=> string(4) "test" ["enc_message"]=> string(0) "" ["dec_message"]=> string(0) "" } </pre>
Output for hhvm-3.21.3
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/jRri9 on line 5 Warning: cannot get key from parameter 1 in /in/jRri9 on line 6 Warning: key parameter is not a valid public key in /in/jRri9 on line 8 Warning: key parameter is not a valid private key in /in/jRri9 on line 11 <pre>array(5) { ["public_key"]=> NULL ["private_key"]=> NULL ["message"]=> string(4) "test" ["enc_message"]=> string(0) "" ["dec_message"]=> string(0) "" } </pre>
Output for hhvm-3.18.5
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/jRri9 on line 5 Warning: cannot get key from parameter 1 in /in/jRri9 on line 6 Warning: key parameter is not a valid public key in /in/jRri9 on line 8 Warning: base64_encode() expects parameter 1 to be string, null given in /in/jRri9 on line 9 Warning: openssl_private_decrypt() expects parameter 1 to be string, null given in /in/jRri9 on line 11 Warning: base64_decode() expects parameter 1 to be string, null given in /in/jRri9 on line 12 <pre>array(5) { ["public_key"]=> NULL ["private_key"]=> NULL ["message"]=> string(4) "test" ["enc_message"]=> NULL ["dec_message"]=> NULL } </pre>