3v4l.org

run code in 300+ PHP versions simultaneously
<?php $private_key_string = <<<__EOF__ -----BEGIN RSA PRIVATE KEY----- MIIBOwIBAAJBANWj431rbsGw3f6rmED2gN0sKaxxDGvFB/M+o6OwnHGEtz7tL1bz J3wUEHzUkt4EelafK7KHNfOZ45mwmeviPn8CAwEAAQJAYj3oKc+Scf1cSHUuIYl5 fruFOmgN9yz21/ORGn/noQc4HS04VynMhzojs5MVIGTFVW1KTn8L4CdQ9iIHHPO4 SQIhAPkb7XKPrCif9XnJSa8l2roMzBYbUXQeeMHW46OzehGlAiEA24zJgypJ3F8t FLqRwXLH0eMr1D50vbPWcmeAWx5hjlMCIQCtPIa8jL2k4tjLgPgFHcYmbI/hL85N eoNwCgj05vOVIQIgScOUlNgpdrwXhmZkwE0TK8aanDXbvTzl6QwzSOn9NvcCIQCS zYIZywZTRueYk3YQCTX3ofnQad7M9X2802tWqm0q6A== -----END RSA PRIVATE KEY----- __EOF__; $public_key_string = <<<__EOF__ -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANWj431rbsGw3f6rmED2gN0sKaxxDGvF B/M+o6OwnHGEtz7tL1bzJ3wUEHzUkt4EelafK7KHNfOZ45mwmeviPn8CAwEAAQ== -----END PUBLIC KEY----- __EOF__; $private_key = openssl_pkey_get_private($private_key_string); $public_key = openssl_pkey_get_public($public_key_string); if (!$private_key) { echo "Cannot get private key\n"; } if (!$public_key) { echo "Cannot get public key\n"; } $input = "abc"; echo "input: $input\n"; openssl_public_encrypt($input, $crypttext, $public_key); openssl_private_decrypt($crypttext, $decoded, $private_key); echo "encrypted: " . base64_encode($crypttext) . "\n"; echo "decrypted: $decoded\n"; $encrypted_encoded = "0aO2tBOUdXrXkASzjnYKydq+WDj6URLvBdKOhxbkXp2/kRTjOb4cGDxBURLGoJPi53rNlNsk8AVEB9e2AkWF1Q=="; $encrypted = base64_decode($encrypted_encoded); openssl_private_decrypt($encrypted, $decrypted, $private_key); echo "decrypted: $decrypted\n";

preferences:
50.12 ms | 402 KiB | 5 Q