3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string='test data'; $output = ''; $encrypt_method = 'AES-256-CTR'; $key = random_bytes(32); // Store long-term $secret_iv = random_bytes(16); $encryption_key = hash_hkdf('sha256', $key, 32, 'encryption'); $authentication_key = hash_hkdf('sha256', $key, 32, 'authentication'); $unauthenticated = openssl_encrypt( $string, $encrypt_method, $encryption_key, OPENSSL_RAW_DATA, $secret_iv ); // NEW: Add an HMAC $hmac = hash_hmac('sha256', $secret_iv . $unauthenticated, $authentication_key, true); $output = base64_encode($hmac . $secret_iv . $unauthenticated); var_dump($output);
Output for 7.1.2 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.25, 7.4.0 - 7.4.13, 8.0.0
Fatal error: Uncaught Error: Call to undefined function openssl_encrypt() in /in/9PN2m:13 Stack trace: #0 {main} thrown in /in/9PN2m on line 13
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.1
Fatal error: Uncaught Error: Call to undefined function hash_hkdf() in /in/9PN2m:10 Stack trace: #0 {main} thrown in /in/9PN2m on line 10
Process exited with code 255.
Output for 5.3.0, 5.6.0 - 5.6.40
Fatal error: Call to undefined function random_bytes() in /in/9PN2m on line 7
Process exited with code 255.

preferences:
148.15 ms | 402 KiB | 191 Q