3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pubkey = '...public key here...'; $privkey = '...private key here...'; function encrypt($data) { global $pubkey, $privkey; if (openssl_public_encrypt($data, $encrypted, $pubkey)) $data = base64_encode($encrypted); else throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?'); return $data; } function decrypt($data) { global $pubkey, $privkey; if (openssl_private_decrypt(base64_decode($data), $decrypted, $privkey)) $data = $decrypted; else $data = ''; return $data; } $e = encrypt('hello'); var_dump($e); var_dump(decrypt($e));

preferences:
55.95 ms | 402 KiB | 5 Q