3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "OPENSSL_KEYTYPE_RSA" in /in/VMLuf:5 Stack trace: #0 {main} thrown in /in/VMLuf on line 5
Process exited with code 255.
Output for 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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/VMLuf on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/VMLuf:9 Stack trace: #0 {main} thrown in /in/VMLuf on line 9
Process exited with code 255.
Output for 7.0.20, 7.1.5 - 7.1.10, 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 7.1.20 - 7.1.33
Notice: Use of undefined constant OPENSSL_KEYTYPE_RSA - assumed 'OPENSSL_KEYTYPE_RSA' in /in/VMLuf on line 5 Fatal error: Uncaught Error: Call to undefined function openssl_pkey_new() in /in/VMLuf:9 Stack trace: #0 {main} thrown in /in/VMLuf on line 9
Process exited with code 255.
Output for 5.4.15 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.6, 7.1.0
plaintext data goes here
Output for 5.4.0 - 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.

preferences:
235.24 ms | 401 KiB | 259 Q