3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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));
based on UIYb3
Output for 7.0.0 - 7.2.0
Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/QQKdm on line 9 Fatal error: Uncaught Exception: Unable to encrypt data. Perhaps it is bigger than the key size? in /in/QQKdm:12 Stack trace: #0 /in/QQKdm(28): encrypt('hello') #1 {main} thrown in /in/QQKdm on line 12
Process exited with code 255.
Output for 5.4.15 - 5.6.21
Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/QQKdm on line 9 Fatal error: Uncaught exception 'Exception' with message 'Unable to encrypt data. Perhaps it is bigger than the key size?' in /in/QQKdm:12 Stack trace: #0 /in/QQKdm(28): encrypt('hello') #1 {main} thrown in /in/QQKdm on line 12
Process exited with code 255.
Output for 5.3.19 - 5.4.14
Fatal error: Call to undefined function openssl_public_encrypt() in /in/QQKdm on line 9
Process exited with code 255.