3v4l.org

run code in 300+ PHP versions simultaneously
<?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\n\nPublic Key:\n$publickey_string\n\n"; $chunk="HelloWorld!"; //if(openssl_private_encrypt($chunk, $encrypted, $privatekey,int $padding = OPENSSL_PKCS1_PADDING)) openssl_private_encrypt($chunk, $encryptedviaprivatekey, $privatekey, OPENSSL_PKCS1_PADDING); echo $chunk . "->" . base64_encode($encryptedviaprivatekey); echo "\n\n";

preferences:
52.43 ms | 402 KiB | 5 Q