3v4l.org

run code in 300+ PHP versions simultaneously
<?php $res = openssl_pkey_new([ 'digest_alg' => 'sha256', 'private_key_bite' => 2048, 'private_key_type' => OPENSSL_TYPE_RSA ]); openssl_pkey_export($res, $privateKey); $publicKey = openssl_pkey_get_details($res)['key']; $message = 'Prime Numbers Rock!'; $aesKey = random_bytes(32); $keyE = hash_hmac('sha256', 'Encryption Key', $aesKey, true); $keyA = hash_hmac('sha256', 'Authentication Key', $aesKey, true); $iv = random_bytes(12); $ciphertext = $iv . openssl_encrypt($message, 'aes-256-ctr', $keyE, OPENSSL_RAW_DATA, $iv); $mac = hash_hmac('sha256', $ciphertext, $keyA, true); $combined = $mac . $ciphertext; $rsaCipher = ''; openssl_public_encrypt($key, $rsaCihper, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); $sendMe = $rsaCipher . $combined; var_dump(strlen($rsaCipher), strlen($combined), strlen($sendMe));
Output for 7.2.0
Warning: Use of undefined constant OPENSSL_TYPE_RSA - assumed 'OPENSSL_TYPE_RSA' (this will throw an Error in a future version of PHP) in /in/7f6uc on line 5 Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/7f6uc on line 7 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/7f6uc on line 8 Warning: openssl_encrypt(): IV passed is only 12 bytes long, cipher expects an IV of precisely 16 bytes, padding with \0 in /in/7f6uc on line 18 Notice: Undefined variable: key in /in/7f6uc on line 23 Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/7f6uc on line 23 int(0) int(63) int(63)
Output for 7.0.20, 7.1.5 - 7.1.10
Notice: Use of undefined constant OPENSSL_TYPE_RSA - assumed 'OPENSSL_TYPE_RSA' in /in/7f6uc on line 5 Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/7f6uc on line 7 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/7f6uc on line 8 Warning: openssl_encrypt(): IV passed is only 12 bytes long, cipher expects an IV of precisely 16 bytes, padding with \0 in /in/7f6uc on line 18 Notice: Undefined variable: key in /in/7f6uc on line 23 Warning: openssl_public_encrypt(): key parameter is not a valid public key in /in/7f6uc on line 23 int(0) int(63) int(63)
Output for 7.0.0 - 7.0.7, 7.1.0
Notice: Use of undefined constant OPENSSL_TYPE_RSA - assumed 'OPENSSL_TYPE_RSA' in /in/7f6uc on line 5 Warning: openssl_encrypt(): IV passed is only 12 bytes long, cipher expects an IV of precisely 16 bytes, padding with \0 in /in/7f6uc on line 18 Notice: Undefined variable: key in /in/7f6uc on line 23 int(0) int(63) int(63)
Output for 5.5.16 - 5.5.36, 5.6.0 - 5.6.28
Notice: Use of undefined constant OPENSSL_TYPE_RSA - assumed 'OPENSSL_TYPE_RSA' in /in/7f6uc on line 6 Fatal error: Call to undefined function random_bytes() in /in/7f6uc on line 13
Process exited with code 255.
Output for 5.5.0 - 5.5.15
Notice: Use of undefined constant OPENSSL_TYPE_RSA - assumed 'OPENSSL_TYPE_RSA' in /in/7f6uc on line 6 Warning: openssl_pkey_new(): Unsupported private key type in /in/7f6uc on line 6 Warning: openssl_pkey_export(): cannot get key from parameter 1 in /in/7f6uc on line 7 Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /in/7f6uc on line 8 Fatal error: Call to undefined function random_bytes() in /in/7f6uc on line 13
Process exited with code 255.

preferences:
107.35 ms | 402 KiB | 80 Q