3v4l.org

run code in 300+ PHP versions simultaneously
<?php $algo = 'aes-256-gcm'; $iv = random_bytes(openssl_cipher_iv_length($algo)); $key = random_bytes(32); // 256 bit //$data = random_bytes(1024); // 1 Kb of random data $data = "well hello there"; $ciphertext = openssl_encrypt( $data, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); // Change 1 bit in ciphertext // $i = rand(0, mb_strlen($ciphertext, '8bit') - 1); // $ciphertext[$i] = $ciphertext[$i] ^ chr(1); echo(base64_encode($ciphertext)); echo('\n'); echo($tag); $decrypt = openssl_decrypt( $ciphertext, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); if (false === $decrypt) { throw new Exception(sprintf( "OpenSSL error: %s", openssl_error_string() )); } printf ("Decryption %s\n", $data === $decrypt ? 'Ok' : 'Failed');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 51
Branch analysis from position: 41
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k0Qju
function name:  (null)
number of ops:  61
compiled vars:  !0 = $algo, !1 = $iv, !2 = $key, !3 = $data, !4 = $ciphertext, !5 = $tag, !6 = $decrypt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'aes-256-gcm'
    3     1        INIT_FCALL                                               'random_bytes'
          2        INIT_FCALL_BY_NAME                                       'openssl_cipher_iv_length'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $8      
          5        SEND_VAR                                                 $8
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !1, $9
    4     8        INIT_FCALL                                               'random_bytes'
          9        SEND_VAL                                                 32
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !2, $11
    6    12        ASSIGN                                                   !3, 'well+hello+there'
    7    13        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
    8    14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !2
   11    17        FETCH_CONSTANT                                   ~14     'OPENSSL_RAW_DATA'
         18        SEND_VAL_EX                                              ~14
    8    19        SEND_VAR_EX                                              !1
         20        SEND_VAR_EX                                              !5
         21        DO_FCALL                                      0  $15     
    7    22        ASSIGN                                                   !4, $15
   18    23        INIT_FCALL                                               'base64_encode'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $17     
         26        ECHO                                                     $17
   19    27        ECHO                                                     '%5Cn'
   20    28        ECHO                                                     !5
   21    29        INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   22    30        SEND_VAR_EX                                              !4
         31        SEND_VAR_EX                                              !0
         32        SEND_VAR_EX                                              !2
   25    33        FETCH_CONSTANT                                   ~18     'OPENSSL_RAW_DATA'
         34        SEND_VAL_EX                                              ~18
   22    35        SEND_VAR_EX                                              !1
         36        SEND_VAR_EX                                              !5
         37        DO_FCALL                                      0  $19     
   21    38        ASSIGN                                                   !6, $19
   29    39        TYPE_CHECK                                    4          !6
         40      > JMPZ                                                     ~21, ->51
   30    41    >   NEW                                              $22     'Exception'
         42        INIT_FCALL                                               'sprintf'
   31    43        SEND_VAL                                                 'OpenSSL+error%3A+%25s'
         44        INIT_FCALL_BY_NAME                                       'openssl_error_string'
         45        DO_FCALL                                      0  $23     
         46        SEND_VAR                                                 $23
         47        DO_ICALL                                         $24     
         48        SEND_VAR_NO_REF_EX                                       $24
         49        DO_FCALL                                      0          
         50      > THROW                                         0          $22
   34    51    >   INIT_FCALL                                               'printf'
         52        SEND_VAL                                                 'Decryption+%25s%0A'
         53        IS_IDENTICAL                                             !3, !6
         54      > JMPZ                                                     ~26, ->57
         55    >   QM_ASSIGN                                        ~27     'Ok'
         56      > JMP                                                      ->58
         57    >   QM_ASSIGN                                        ~27     'Failed'
         58    >   SEND_VAL                                                 ~27
         59        DO_ICALL                                                 
         60      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.59 ms | 1400 KiB | 21 Q