3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (PHP_VERSION_ID < 70000) exit; $res = openssl_pkey_new([ 'digest_alg' => 'sha256', 'private_key_bite' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA ]); openssl_pkey_export($res, $privateKey); $publicKey = openssl_pkey_get_details($res)['key']; $message = 'Prime Numbers Rock!'; $aesKey = random_bytes(32); // Basically a poor-man's HKDF by just using HMAC $keyE = hash_hmac('sha256', 'Encryption Key', $aesKey, true); $keyA = hash_hmac('sha256', 'Authentication Key', $aesKey, true); $iv = random_bytes(16); $ciphertext = openssl_encrypt($message, 'aes-256-ctr', $keyE, OPENSSL_RAW_DATA, $iv); $mac = hash_hmac('sha256', $iv .$ciphertext, $keyA, true); $combined = $mac . $iv . $ciphertext; $rsaCipher = ''; openssl_public_encrypt($aesKey, $rsaCipher, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); $sendMe = $rsaCipher . $combined; var_dump(base64_encode($sendMe)); ## DECRYPTION ## $rsaPart = mb_substr($sendMe, 0, 256, '8bit'); // Assuming 2048-bit RSA $aesPart = mb_substr($sendMe, 256, null, '8bit'); $mac = mb_substr($aesPart, 0, 32, '8bit'); $iv = mb_substr($aesPart, 32, 16, '8bit'); $cipher = mb_substr($aesPart, 48, null, '8bit'); $aesKey = ''; openssl_private_decrypt($rsaPart, $aesKey, $privateKey, OPENSSL_PKCS1_OAEP_PADDING); $keyE = hash_hmac('sha256', 'Encryption Key', $aesKey, true); $keyA = hash_hmac('sha256', 'Authentication Key', $aesKey, true); $calc = hash_hmac('sha256', $iv . $cipher, $keyA, true); if (!hash_equals($calc, $mac)) { throw new Exception('MAC validation failure'); } $decrypted = openssl_decrypt($cipher, 'aes-256-ctr', $keyE, OPENSSL_RAW_DATA, $iv); var_dump($decrypted); // string(19) "Prime Numbers Rock!"

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.1.70.0070.00317.26
7.1.60.0110.01119.90
7.1.50.0070.00717.02
7.1.00.0000.14722.67
7.0.200.0210.00914.75
7.0.70.1000.16020.22
7.0.60.0730.15020.32
7.0.50.0700.10720.72
7.0.40.0800.19020.57
7.0.30.0700.11720.76
7.0.20.0670.09720.63
7.0.10.0700.18020.47
7.0.00.0670.10320.53
5.6.280.0030.07020.94
5.6.220.0670.07720.73
5.6.210.0630.06320.65
5.6.200.0670.06321.11
5.6.190.0670.05321.03
5.6.180.0800.04721.17
5.6.170.0600.06321.03
5.6.160.0670.06021.09
5.6.150.0730.07721.18
5.6.140.0630.07021.02
5.6.130.0770.07321.18
5.6.120.0130.06721.11
5.6.110.0330.06321.00
5.6.100.0630.06321.15
5.6.90.0700.06020.99
5.6.80.0600.06020.56
5.6.70.0600.05320.48
5.6.60.0700.04320.38
5.6.50.0600.06020.39
5.6.40.0670.06020.56
5.6.30.0770.07020.39
5.6.20.0630.06320.38
5.6.10.0630.05320.50
5.6.00.0600.05720.37
5.5.360.0530.06020.51
5.5.350.0570.06720.43
5.5.340.0570.06320.85
5.5.330.0670.06320.80
5.5.320.0670.06020.87
5.5.310.0530.06020.96
5.5.300.0630.06020.87
5.5.290.0830.07720.90
5.5.280.0100.06720.96
5.5.270.0630.06720.99
5.5.260.0630.06320.86
5.5.250.0700.06020.64
5.5.240.0600.06320.34
5.5.230.0700.06720.28
5.5.220.0570.06020.16
5.5.210.0530.06020.34
5.5.200.0730.04720.23
5.5.190.0600.06320.18
5.5.180.0670.05020.18
5.5.160.0570.05720.19
5.5.150.0570.05720.32
5.5.140.0700.04320.30
5.5.130.0630.05720.19
5.5.120.0570.06020.27
5.5.110.0700.04720.21
5.5.100.0630.05320.25
5.5.90.0670.05319.98
5.5.80.0600.05320.14
5.5.70.0570.05720.21
5.5.60.0700.04320.13
5.5.50.0670.04720.09
5.5.40.0570.05320.13
5.5.30.0630.07320.00
5.5.20.0630.05020.12
5.5.10.0730.06720.16
5.5.00.0770.07320.12

preferences:
44.67 ms | 403 KiB | 5 Q