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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9PN2m
function name:  (null)
number of ops:  52
compiled vars:  !0 = $string, !1 = $output, !2 = $encrypt_method, !3 = $key, !4 = $secret_iv, !5 = $encryption_key, !6 = $authentication_key, !7 = $unauthenticated, !8 = $hmac
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'test+data'
    5     1        ASSIGN                                                   !1, ''
    6     2        ASSIGN                                                   !2, 'AES-256-CTR'
    7     3        INIT_FCALL                                               'random_bytes'
          4        SEND_VAL                                                 32
          5        DO_ICALL                                         $12     
          6        ASSIGN                                                   !3, $12
    9     7        INIT_FCALL                                               'random_bytes'
          8        SEND_VAL                                                 16
          9        DO_ICALL                                         $14     
         10        ASSIGN                                                   !4, $14
   10    11        INIT_FCALL                                               'hash_hkdf'
         12        SEND_VAL                                                 'sha256'
         13        SEND_VAR                                                 !3
         14        SEND_VAL                                                 32
         15        SEND_VAL                                                 'encryption'
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !5, $16
   11    18        INIT_FCALL                                               'hash_hkdf'
         19        SEND_VAL                                                 'sha256'
         20        SEND_VAR                                                 !3
         21        SEND_VAL                                                 32
         22        SEND_VAL                                                 'authentication'
         23        DO_ICALL                                         $18     
         24        ASSIGN                                                   !6, $18
   13    25        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
   14    26        SEND_VAR_EX                                              !0
         27        SEND_VAR_EX                                              !2
         28        SEND_VAR_EX                                              !5
   17    29        FETCH_CONSTANT                                   ~20     'OPENSSL_RAW_DATA'
         30        SEND_VAL_EX                                              ~20
   14    31        SEND_VAR_EX                                              !4
         32        DO_FCALL                                      0  $21     
   13    33        ASSIGN                                                   !7, $21
   22    34        INIT_FCALL                                               'hash_hmac'
         35        SEND_VAL                                                 'sha256'
         36        CONCAT                                           ~23     !4, !7
         37        SEND_VAL                                                 ~23
         38        SEND_VAR                                                 !6
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $24     
         41        ASSIGN                                                   !8, $24
   23    42        INIT_FCALL                                               'base64_encode'
         43        CONCAT                                           ~26     !8, !4
         44        CONCAT                                           ~27     ~26, !7
         45        SEND_VAL                                                 ~27
         46        DO_ICALL                                         $28     
         47        ASSIGN                                                   !1, $28
   25    48        INIT_FCALL                                               'var_dump'
         49        SEND_VAR                                                 !1
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.01 ms | 1405 KiB | 23 Q