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(mb_strlen($ciphertext, '8bit')); echo("\n"); $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 = 46, Position 2 = 56
Branch analysis from position: 46
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Vvjj
function name:  (null)
number of ops:  66
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                                                     '%0A'
   20    28        INIT_FCALL                                               'mb_strlen'
         29        SEND_VAR                                                 !4
         30        SEND_VAL                                                 '8bit'
         31        DO_ICALL                                         $18     
         32        ECHO                                                     $18
   21    33        ECHO                                                     '%0A'
   23    34        INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   24    35        SEND_VAR_EX                                              !4
         36        SEND_VAR_EX                                              !0
         37        SEND_VAR_EX                                              !2
   27    38        FETCH_CONSTANT                                   ~19     'OPENSSL_RAW_DATA'
         39        SEND_VAL_EX                                              ~19
   24    40        SEND_VAR_EX                                              !1
         41        SEND_VAR_EX                                              !5
         42        DO_FCALL                                      0  $20     
   23    43        ASSIGN                                                   !6, $20
   31    44        TYPE_CHECK                                    4          !6
         45      > JMPZ                                                     ~22, ->56
   32    46    >   NEW                                              $23     'Exception'
         47        INIT_FCALL                                               'sprintf'
   33    48        SEND_VAL                                                 'OpenSSL+error%3A+%25s'
         49        INIT_FCALL_BY_NAME                                       'openssl_error_string'
         50        DO_FCALL                                      0  $24     
         51        SEND_VAR                                                 $24
         52        DO_ICALL                                         $25     
         53        SEND_VAR_NO_REF_EX                                       $25
         54        DO_FCALL                                      0          
         55      > THROW                                         0          $23
   37    56    >   INIT_FCALL                                               'printf'
         57        SEND_VAL                                                 'Decryption+%25s%0A'
         58        IS_IDENTICAL                                             !3, !6
         59      > JMPZ                                                     ~27, ->62
         60    >   QM_ASSIGN                                        ~28     'Ok'
         61      > JMP                                                      ->63
         62    >   QM_ASSIGN                                        ~28     'Failed'
         63    >   SEND_VAL                                                 ~28
         64        DO_ICALL                                                 
         65      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.43 ms | 1400 KiB | 23 Q