3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encrypt_decrypt($action, $string, $secret_key, $secret_iv) { $output = false; if (!extension_loaded('openssl')) { return $string; } $encrypt_method = "AES-256-CBC"; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); if($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if($action == 'decrypt'){ $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } echo encrypt_decrypt('decrypt', 'NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=', ENCRYPTION_KEY, ENCRYPTION_VI);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p0m5m
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'encrypt_decrypt'
          1        SEND_VAL                                                 'decrypt'
          2        SEND_VAL                                                 'NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0%3D'
          3        FETCH_CONSTANT                                   ~0      'ENCRYPTION_KEY'
          4        SEND_VAL                                                 ~0
          5        FETCH_CONSTANT                                   ~1      'ENCRYPTION_VI'
          6        SEND_VAL                                                 ~1
          7        DO_FCALL                                      0  $2      
          8        ECHO                                                     $2
          9      > RETURN                                                   1

Function encrypt_decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 42
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 55
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
filename:       /in/p0m5m
function name:  encrypt_decrypt
number of ops:  57
compiled vars:  !0 = $action, !1 = $string, !2 = $secret_key, !3 = $secret_iv, !4 = $output, !5 = $encrypt_method, !6 = $key, !7 = $iv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    3     4        ASSIGN                                                   !4, <false>
    5     5        INIT_FCALL                                               'extension_loaded'
          6        SEND_VAL                                                 'openssl'
          7        DO_ICALL                                         $9      
          8        BOOL_NOT                                         ~10     $9
          9      > JMPZ                                                     ~10, ->11
    6    10    > > RETURN                                                   !1
    9    11    >   ASSIGN                                                   !5, 'AES-256-CBC'
   12    12        INIT_FCALL                                               'hash'
         13        SEND_VAL                                                 'sha256'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !6, $12
   15    17        INIT_FCALL                                               'substr'
         18        INIT_FCALL                                               'hash'
         19        SEND_VAL                                                 'sha256'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $14     
         22        SEND_VAR                                                 $14
         23        SEND_VAL                                                 0
         24        SEND_VAL                                                 16
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !7, $15
   16    27        IS_EQUAL                                                 !0, 'encrypt'
         28      > JMPZ                                                     ~17, ->42
   17    29    >   INIT_FCALL_BY_NAME                                       'openssl_encrypt'
         30        SEND_VAR_EX                                              !1
         31        SEND_VAR_EX                                              !5
         32        SEND_VAR_EX                                              !6
         33        SEND_VAL_EX                                              0
         34        SEND_VAR_EX                                              !7
         35        DO_FCALL                                      0  $18     
         36        ASSIGN                                                   !4, $18
   18    37        INIT_FCALL                                               'base64_encode'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $20     
         40        ASSIGN                                                   !4, $20
   16    41      > JMP                                                      ->55
   19    42    >   IS_EQUAL                                                 !0, 'decrypt'
         43      > JMPZ                                                     ~22, ->55
   20    44    >   INIT_FCALL_BY_NAME                                       'openssl_decrypt'
         45        INIT_FCALL                                               'base64_decode'
         46        SEND_VAR                                                 !1
         47        DO_ICALL                                         $23     
         48        SEND_VAR_NO_REF_EX                                       $23
         49        SEND_VAR_EX                                              !5
         50        SEND_VAR_EX                                              !6
         51        SEND_VAL_EX                                              0
         52        SEND_VAR_EX                                              !7
         53        DO_FCALL                                      0  $24     
         54        ASSIGN                                                   !4, $24
   23    55    > > RETURN                                                   !4
   24    56*     > RETURN                                                   null

End of function encrypt_decrypt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.44 ms | 1444 KiB | 19 Q