3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. class Cryptor { protected $method = 'AES-128-CTR'; // default private $key; protected function iv_bytes() { return openssl_cipher_iv_length($this->method); } public function __construct($key = FALSE, $method = FALSE) { if(!$key) { // if you don't supply your own key, this will be the default $key = gethostname() . "|" . ip2long($_SERVER['SERVER_ADDR']); } if(ctype_print($key)) { // convert key to binary format $this->key = openssl_digest($key, 'SHA256', TRUE); } else { $this->key = $key; } if($method) { if(in_array($method, openssl_get_cipher_methods())) { $this->method = $method; } else { die(__METHOD__ . ": unrecognised encryption method: {$method}"); } } } public function encrypt($data) { $iv = openssl_random_pseudo_bytes($this->iv_bytes()); $encrypted_string = bin2hex($iv) . openssl_encrypt($data, $this->method, $this->key, 0, $iv); return $encrypted_string; } // decrypt encrypted string public function decrypt($data) { $iv_strlen = 2 * $this->iv_bytes(); if(preg_match("/^(.{" . $iv_strlen . "})(.+)$/", $data, $regs)) { list(, $iv, $crypted_string) = $regs; $decrypted_string = openssl_decrypt($crypted_string, $this->method, $this->key, 0, hex2bin($iv)); return $decrypted_string; } else { return FALSE; } } } $token = "The quick brown fox jumps over the lazy dog."; $encryption_key = 'CKXH2U9RPY3EFD70TLS1ZG4N8WQBOVI6AMJ5'; $cryptor = new Cryptor($encryption_key); $crypted_token = $cryptor->encrypt($token); unset($token); echo $crypted_token;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J0Wgs
function name:  (null)
number of ops:  13
compiled vars:  !0 = $token, !1 = $encryption_key, !2 = $cryptor, !3 = $crypted_token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   ASSIGN                                                   !0, 'The+quick+brown+fox+jumps+over+the+lazy+dog.'
   62     1        ASSIGN                                                   !1, 'CKXH2U9RPY3EFD70TLS1ZG4N8WQBOVI6AMJ5'
   63     2        NEW                                              $6      'Cryptor'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   64     6        INIT_METHOD_CALL                                         !2, 'encrypt'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $9      
          9        ASSIGN                                                   !3, $9
   65    10        UNSET_CV                                                 !0
   66    11        ECHO                                                     !3
   67    12      > RETURN                                                   1

Class Cryptor:
Function iv_bytes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J0Wgs
function name:  iv_bytes
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL_BY_NAME                                       'openssl_cipher_iv_length'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'method'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   15     6*     > RETURN                                                   null

End of function iv_bytes

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 43
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 43
Branch analysis from position: 29
Branch analysis from position: 43
Branch analysis from position: 14
filename:       /in/J0Wgs
function name:  __construct
number of ops:  44
compiled vars:  !0 = $key, !1 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV_INIT                                        !0      <false>
          1        RECV_INIT                                        !1      <false>
   19     2        BOOL_NOT                                         ~2      !0
          3      > JMPZ                                                     ~2, ->14
   21     4    >   INIT_FCALL                                               'gethostname'
          5        DO_ICALL                                         $3      
          6        CONCAT                                           ~4      $3, '%7C'
          7        INIT_FCALL                                               'ip2long'
          8        FETCH_R                      global              ~5      '_SERVER'
          9        FETCH_DIM_R                                      ~6      ~5, 'SERVER_ADDR'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12        CONCAT                                           ~8      ~4, $7
         13        ASSIGN                                                   !0, ~8
   23    14    >   INIT_FCALL                                               'ctype_print'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $10     
         17      > JMPZ                                                     $10, ->26
   25    18    >   INIT_FCALL_BY_NAME                                       'openssl_digest'
         19        SEND_VAR_EX                                              !0
         20        SEND_VAL_EX                                              'SHA256'
         21        SEND_VAL_EX                                              <true>
         22        DO_FCALL                                      0  $12     
         23        ASSIGN_OBJ                                               'key'
         24        OP_DATA                                                  $12
         25      > JMP                                                      ->28
   27    26    >   ASSIGN_OBJ                                               'key'
         27        OP_DATA                                                  !0
   29    28    > > JMPZ                                                     !1, ->43
   30    29    >   INIT_FCALL                                               'in_array'
         30        SEND_VAR                                                 !1
         31        INIT_FCALL_BY_NAME                                       'openssl_get_cipher_methods'
         32        DO_FCALL                                      0  $14     
         33        SEND_VAR                                                 $14
         34        DO_ICALL                                         $15     
         35      > JMPZ                                                     $15, ->39
   31    36    >   ASSIGN_OBJ                                               'method'
         37        OP_DATA                                                  !1
         38      > JMP                                                      ->43
   33    39    >   NOP                                                      
         40        FAST_CONCAT                                      ~17     '%3A+unrecognised+encryption+method%3A+', !1
         41        CONCAT                                           ~18     'Cryptor%3A%3A__construct', ~17
         42      > EXIT                                                     ~18
   36    43    > > RETURN                                                   null

End of function __construct

Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J0Wgs
function name:  encrypt
number of ops:  25
compiled vars:  !0 = $data, !1 = $iv, !2 = $encrypted_string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
          2        INIT_METHOD_CALL                                         'iv_bytes'
          3        DO_FCALL                                      0  $3      
          4        SEND_VAR_NO_REF_EX                                       $3
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   41     7        INIT_FCALL                                               'bin2hex'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
         11        SEND_VAR_EX                                              !0
         12        CHECK_FUNC_ARG                                           
         13        FETCH_OBJ_FUNC_ARG                               $7      'method'
         14        SEND_FUNC_ARG                                            $7
         15        CHECK_FUNC_ARG                                           
         16        FETCH_OBJ_FUNC_ARG                               $8      'key'
         17        SEND_FUNC_ARG                                            $8
         18        SEND_VAL_EX                                              0
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $9      
         21        CONCAT                                           ~10     $6, $9
         22        ASSIGN                                                   !2, ~10
   42    23      > RETURN                                                   !2
   43    24*     > RETURN                                                   null

End of function encrypt

Function decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 36
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J0Wgs
function name:  decrypt
number of ops:  38
compiled vars:  !0 = $data, !1 = $iv_strlen, !2 = $regs, !3 = $iv, !4 = $crypted_string, !5 = $decrypted_string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        INIT_METHOD_CALL                                         'iv_bytes'
          2        DO_FCALL                                      0  $6      
          3        MUL                                              ~7      $6, 2
          4        ASSIGN                                                   !1, ~7
   49     5        INIT_FCALL                                               'preg_match'
          6        CONCAT                                           ~9      '%2F%5E%28.%7B', !1
          7        CONCAT                                           ~10     ~9, '%7D%29%28.%2B%29%24%2F'
          8        SEND_VAL                                                 ~10
          9        SEND_VAR                                                 !0
         10        SEND_REF                                                 !2
         11        DO_ICALL                                         $11     
         12      > JMPZ                                                     $11, ->36
   50    13    >   QM_ASSIGN                                        ~12     !2
         14        FETCH_LIST_R                                     $13     ~12, 1
         15        ASSIGN                                                   !3, $13
         16        FETCH_LIST_R                                     $15     ~12, 2
         17        ASSIGN                                                   !4, $15
         18        FREE                                                     ~12
   51    19        INIT_FCALL_BY_NAME                                       'openssl_decrypt'
         20        SEND_VAR_EX                                              !4
         21        CHECK_FUNC_ARG                                           
         22        FETCH_OBJ_FUNC_ARG                               $17     'method'
         23        SEND_FUNC_ARG                                            $17
         24        CHECK_FUNC_ARG                                           
         25        FETCH_OBJ_FUNC_ARG                               $18     'key'
         26        SEND_FUNC_ARG                                            $18
         27        SEND_VAL_EX                                              0
         28        INIT_FCALL                                               'hex2bin'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $19     
         31        SEND_VAR_NO_REF_EX                                       $19
         32        DO_FCALL                                      0  $20     
         33        ASSIGN                                                   !5, $20
   52    34      > RETURN                                                   !5
         35*       JMP                                                      ->37
   54    36    > > RETURN                                                   <false>
   56    37*     > RETURN                                                   null

End of function decrypt

End of class Cryptor.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.58 ms | 1408 KiB | 27 Q