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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.14 ms | 945 KiB | 24 Q