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";
Output for 7.1.20 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
Fatal error: Uncaught Error: Call to undefined function openssl_pkey_get_private() in /in/eqe8c:22 Stack trace: #0 {main} thrown in /in/eqe8c on line 22
Process exited with code 255.
Output for 7.1.10
input: abc encrypted: yBpA9clGGIHNpSD4BY061iDkb82KpBAqwZT3N0UZl6PEKPkgM56WERKh1Ir+Tt4Itsa7MbaRPRJ023UycgbR4Q== decrypted: abc decrypted:
Output for 7.1.7
input: abc encrypted: KFRb9R1wzM6OSinb+IoKrc4L+juT4iJ6fpMnV2sYogaZgUYkXQZ8uuuT/Ox5QdxFxnMi4czARjXyG3fjGff3Ng== decrypted: abc decrypted:
Output for 7.1.6
input: abc encrypted: h95l/UyWD13fh/0j5gi/2iJTuaQ5+NoXe/3WrJaRJzOzF8V4XbVa0itmek9M4Gra0UN6bnv/y1cGcNQuHZZ0ow== decrypted: abc decrypted:
Output for 7.1.5
input: abc encrypted: TcxfJG4UOu2hT5cP428iE7hMxBWPZJQ8EuteVioM2c50hQAIgFbZw2IDXbfP4gQAvyQf/9yfAJut6GR0FVzdww== decrypted: abc decrypted:
Output for 7.1.0
input: abc encrypted: mLcPIBRAnknPCiwfD5186v8NX17ClQ42SrDjH0CpU2GQZG2RrBBj7ayAMXJAeOhKv8yQygZjI4sGMVXqeKQQ+Q== decrypted: abc decrypted:
Output for 7.0.20
input: abc encrypted: K/4KvcrCsN0lVgj9Ctnq7i1v++JAuOY6d+CV7h6JUZuKAhBCK4KNSOn8wWAkQDPhS0i9wYb9H8xkyCi5Zuv8sg== decrypted: abc decrypted:
Output for 7.0.6
input: abc encrypted: pGxFx7JYFeqZclAdyY7CcHmpuGvXm1nwUXVEXqQW31KkzN1HXCKQGp9y0alTHBm/utx1bue7yrpzkiltlukNWg== decrypted: abc decrypted:
Output for 7.0.5
input: abc encrypted: FHZbEjG7lmRkXorkLe130KKnWiLRwmGn+H4Oh4VtMfu42/hXYDtyHJr+LEbpG+b6iyR5KMTIqu5zqu3BxIyKWg== decrypted: abc decrypted:
Output for 7.0.4
input: abc encrypted: GfFeGQtBJUrNlJwCn4YrMgAttsKuN9zJ20ESNdt1VUkWiylRvNW7f2TQxp0SqT82xowIcy4pxbefIRJULqIKlQ== decrypted: abc decrypted:
Output for 7.0.3
input: abc encrypted: q3mI+ED57DD5L2/DNgoF4wJxjdXi7b/tQ8bqFvOVpN/B3TM8F2m/QMFaMSodh3gSjcUUHj1NBp54/khd+zg9Eg== decrypted: abc decrypted:
Output for 7.0.2
input: abc encrypted: VzdrXu09aN2xwGMcNDe+WT0yOegRD82vrolsTFyzZvIOOnoOOMwhGQE5I1lmIeckBgKaHWAcdebFOD9GE6gSpQ== decrypted: abc decrypted:
Output for 7.0.1
input: abc encrypted: ir6B+gPtdxSYwoaPaSSINtfByWfpX6cgul2y3d1TlPhoBvMKTtz11PPIQ26v0XGuELbpSRbc0zv/yx4+pwTBvw== decrypted: abc decrypted:
Output for 7.0.0
input: abc encrypted: m2Jl2gcWOGWQ0VfGGm+SIRgLrMXIe519oDriJr/U15g3W3shAepZbbHitHzpPb1tM4TF02vLffP6ZMKtHTHRwQ== decrypted: abc decrypted:
Output for 5.6.28
input: abc encrypted: Er0QZOffAtSziKlt8qbDL1GAMviVGf2Sj1lcLBZtXivhvoj/LKsQapEJu0zzJxL7mIqXT7+iUgh3/42qjJa8og== decrypted: abc decrypted:
Output for 5.6.21
input: abc encrypted: z1TxU69g/MyDE73uMJ9Rb+cPrpAX3a3dGLRQU7M1oZMJTkYi4S2DQ9Ab/9oncpGgYO1ltPjLx0JxFr9rIonk+w== decrypted: abc decrypted:
Output for 5.6.20
input: abc encrypted: cnQGwFuq7uitGpFDCH3UcodNJ3X3XU3AGFmx5FJ54WRi9DJ+wSGUDbxyttiXC41g7dep72Sf4rZURO6271p7tw== decrypted: abc decrypted:
Output for 5.6.19
input: abc encrypted: G0jR3fpWAao506B+xYxt84zRzR91aShjZ9Fg0FnoBvu7ZM3o4LXKqDl+2U/Aw5YA8Nc0OLsZjm3imfXv3JxCFw== decrypted: abc decrypted:
Output for 5.6.18
input: abc encrypted: rIlaeT1ayHbDqzwnG+Ev5qhAvc9o3B5/F6XTgGJBTBf1M6l5TX3I5OJVivFBqUiQFz10us05lvfOCmvxW+hyGQ== decrypted: abc decrypted:
Output for 5.6.17
input: abc encrypted: FyLlIUwJ3LexqayFbYTxAUbDGQBju087ABVyR8ofMAv0cy1+PPlASqijNSBLIvm35RJ6NlE1Zbx46E2QCPAUaA== decrypted: abc decrypted:
Output for 5.6.16
input: abc encrypted: gIdQ6zxtY9Yb/AwZA8mC+b1TuLw84d9JYm8hWdu1uuHGv77vbhg33J/ODgSH5Vw2RdFCv3v/t6NyQ9yk5uzKCQ== decrypted: abc decrypted:
Output for 5.6.15
input: abc encrypted: 0/icPnwPoc1lBVSctFYL1wGPwdeA22ePBcovJIRNRRe1dxmHu9ioYN+mNfm+7g61IRQz9Xg/AyFu3EUJbWHOnQ== decrypted: abc decrypted:
Output for 5.6.14
input: abc encrypted: z24xNlfsU2NivAWrquDz2Zz4CLZoiKsQLjo6cjU8KWlA0hrfFltGpwuMR70D798WK4PwoRmF1mtvbQlWCQbK2g== decrypted: abc decrypted:
Output for 5.6.13
input: abc encrypted: E2roWD5GhUo3yS6uTXmRlb4Po1bJKrylA4XjV93l+NMXOiEY/D+jHIEzWUhycrRHXlddWao2q+um0rwSHtWnRQ== decrypted: abc decrypted:
Output for 5.6.12
input: abc encrypted: YHeMire713sa//OjkocCWtL/N9GDZ4vdxvHYifaGimlFLi8/5vvmi+RgCkZOC6BnFXP80cmwKp6HrT+EBeGJbQ== decrypted: abc decrypted:
Output for 5.6.11
input: abc encrypted: HKF3RkNeiLi4xFhJ8nT0jsxXE9a9hNqU1QmOEI7yOcB4BGVapf4dAiHwXd3X4PG5MfprBcBgDFHp0QlC2HYP4w== decrypted: abc decrypted:
Output for 5.6.10
input: abc encrypted: c9oamKmntYzHamNQB67fYcWzYHB1+bPchMeegJbjrAk7Jvt3trBOpxhc4za1uRy5IjaRu4HUWuDs3jWKL7pk9Q== decrypted: abc decrypted:
Output for 5.6.9
input: abc encrypted: hxOvgACtGU8SXG+RxPpP/aFmbsQ9ohPDeQ2TtOfr8UGZaqTrr2pHdl9XAf5RhKHDt8Uyy4us5LBzvOlzD2zVNA== decrypted: abc decrypted:
Output for 5.6.8
input: abc encrypted: vT8hwFPxY6udZFZAOvxbTEgwosSNrpWsvaVqSs1NJi3baIyKQTAzsTcBdqCP7cZJYNt6wWEKzVlksg8QuhChiw== decrypted: abc decrypted:
Output for 5.5.35
input: abc encrypted: quxkNZTRfljs+xJo/8e93x41wOFSJdOYpMmk/qzD0maAHHBSFPTEN+TAh/ubz6NonAEV1TZORLhG5WIowpJ2Rw== decrypted: abc decrypted:
Output for 5.5.34
input: abc encrypted: Ur/Igquq+Amm/Se/NCLd22q9F2e4PzrZYVQQp5MD5DvzlwacIShybdwrbR/tg33unQhcBF3DLof1/g2L5Df0hg== decrypted: abc decrypted:
Output for 5.5.33
input: abc encrypted: CgOQab6TznkaO2NviWd1zm6Hq9TpvKUZkNbKDa3tSMS3We0tkikll6Zn/OgSMKjVYQMogYbnRBfTvfRlHf2LiA== decrypted: abc decrypted:
Output for 5.5.32
input: abc encrypted: JSchb4Q2PZw6zHL7CVUk+SUrbwTbQm9YsZNp527Qow0rj7PVo1RkQ6hg5x+zBB8RwQ0SNvUu1UEC6K7aRy9X3A== decrypted: abc decrypted:
Output for 5.5.31
input: abc encrypted: PXLsm8t6Q0zTJYBJaUDnZ+NSrragDjIAodJ89Xkazp70dmYdr2mPfFWeRNmkAVo0tw+7iqVJLYiRK1YvvpY4Vg== decrypted: abc decrypted:
Output for 5.5.30
input: abc encrypted: olSiXXN7CMAg0INbOOjbMBUEbJRm2qrcGaVk5DSE53Z4x0puGadzcGni+uBWJGo0mxOuVSLbHcCksv1DE/spDw== decrypted: abc decrypted:
Output for 5.5.29
input: abc encrypted: cIVASOxxGPn19ucETF3o4iqObBx3JAVAzwUXby6G1msaXHn5rYdYCClZ9lHnBA4av+JkBX+3IIb9ePEkdpaJFw== decrypted: abc decrypted:
Output for 5.5.28
input: abc encrypted: Y3IJ0QZicQEeJbMk5Gm9Znms46va9g2Mmr+lGqD4cPsy/iL6RAWOdrhxXFCPkbERfctkfXz6QGsfXDVjKr/deQ== decrypted: abc decrypted:
Output for 5.5.27
input: abc encrypted: JsVFK/Dx3YksTdGnn62RBqEZst3K8V4OPbxGYwCaxbwxn+NOzLnvUZ6iwdMnmYgyhZ+yytyqA/R462/bIha+yg== decrypted: abc decrypted:
Output for 5.5.26
input: abc encrypted: fgEFvyBcV7ebLortzxHFGxTlIEoOXSrP0llvq8vXJv6iUNOJI43iqYfQxmMCzd4yP0gMu6oRhUGFdPKX8+xEYw== decrypted: abc decrypted:
Output for 5.5.25
input: abc encrypted: DDLCWyzt/SpjLQe6QZZwY0tOtE0IZdtVnZwiVVvgCv9nCADKiKMk5jWn1wryP/phpd5mTVsEU3Gwdwhf4QnDLQ== decrypted: abc decrypted:
Output for 5.5.24
input: abc encrypted: ualVN7jJ8QBG1ew9A+mQngwt6Z1V27SNKL8mRx+SosO/btwifgsRAiW8g8TBv9XJDxstWawzLioCwbbKuP1O6Q== decrypted: abc decrypted:

preferences:
188.17 ms | 402 KiB | 233 Q