3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class EncDec * @package App\Http */ class EncDec { private $key; protected $iv_size; protected $iv; protected $project_id; protected $user_id; protected $type; protected $extra_param; public function __construct() { # --- ENCRYPTION --- # the key should be random binary, use scrypt, bcrypt or PBKDF2 to # convert a string into a key # key is specified using hexadecimal $this->key = hash('sha256',"prelaunch",TRUE); # create a random IV to use with CBC encoding $this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND); } /** * @param $project_id * @param $user_id * @param $type * @param array $extra_param * @return string */ public function encryptData($project_id, $user_id, $type = "user", array $extra_param = array()) { $this->project_id = $project_id; $this->user_id = $user_id; $this->type = $type; $this->extra_param = $extra_param; $encrypting_array = [ "p" => $this->project_id, "i" => $this->user_id, "t" => $this->type, "e" => $this->extra_param ]; $encrypting_text = http_build_query($encrypting_array); $output = $this->encrypt($encrypting_text); return $output; } public function encrypt_data($data) { $output = $this->encrypt($data); return $output; } public function decrypt_data($encrypted_text) { $encrypted_text = base64_decode(str_replace(["-", "_"], ["+", "/"], $encrypted_text)); return rtrim($this->decrypt($encrypted_text)); } public function decryptData($encrypted_text) { // try { $encrypted_text = base64_decode(str_replace(["-", "_"], ["+", "/"], $encrypted_text)); $decrypted_text = $this->decrypt($encrypted_text); parse_str($decrypted_text, $return_decrypted_array); return $return_decrypted_array; // } catch (DecryptException $e) { // throw new Exception("You tried to change the delicate internal behavior of my system"); // } } public function decrypt($string) { # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($string, 0, $this->iv_size); # retrieves the cipher text (everything except the $iv_size in the front) $string = substr($string, $this->iv_size); # may remove 00h valued characters from end of plain text $output = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $iv_dec); return $output; } public function encrypt($string) { # creates a cipher text compatible with AES (Rijndael block size = 128) # to keep the text confidential # only suitable for encoded input that never ends with value 00h # (because of default zero padding) $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $this->iv); # prepend the IV for it to be available for decryption $output = $this->iv . $output; # encode the resulting cipher text so it can be represented by a string $output = base64_encode($output); # === WARNING === # Resulting cipher text has no integrity or authenticity added # and is not protected against padding oracle attacks. $encrypted_text = str_replace(["+", "/", "="], ["-", "_", ""], $output); return $encrypted_text; } } $enc_dec = new EncDec(); echo $enc_dec->encrypt("Narendra"); echo $enc_dec->decrypt(1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  (null)
number of ops:  12
compiled vars:  !0 = $enc_dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  110     0  E >   NEW                                              $1      'EncDec'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
  111     3        INIT_METHOD_CALL                                         !0, 'encrypt'
          4        SEND_VAL_EX                                              'Narendra'
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
  112     7        INIT_METHOD_CALL                                         !0, 'decrypt'
          8        SEND_VAL_EX                                              1
          9        DO_FCALL                                      0  $5      
         10        ECHO                                                     $5
         11      > RETURN                                                   1

Class EncDec:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  __construct
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'hash'
          1        SEND_VAL                                                 'sha256'
          2        SEND_VAL                                                 'prelaunch'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $1      
          5        ASSIGN_OBJ                                               'key'
          6        OP_DATA                                                  $1
   24     7        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
          8        FETCH_CONSTANT                                   ~3      'MCRYPT_RIJNDAEL_256'
          9        SEND_VAL_EX                                              ~3
         10        FETCH_CONSTANT                                   ~4      'MCRYPT_MODE_CBC'
         11        SEND_VAL_EX                                              ~4
         12        DO_FCALL                                      0  $5      
         13        ASSIGN_OBJ                                               'iv_size'
         14        OP_DATA                                                  $5
   25    15        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $7      'iv_size'
         18        SEND_FUNC_ARG                                            $7
         19        FETCH_CONSTANT                                   ~8      'MCRYPT_RAND'
         20        SEND_VAL_EX                                              ~8
         21        DO_FCALL                                      0  $9      
         22        ASSIGN_OBJ                                               'iv'
         23        OP_DATA                                                  $9
   26    24      > RETURN                                                   null

End of function __construct

Function encryptdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  encryptData
number of ops:  31
compiled vars:  !0 = $project_id, !1 = $user_id, !2 = $type, !3 = $extra_param, !4 = $encrypting_array, !5 = $encrypting_text, !6 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'user'
          3        RECV_INIT                                        !3      <array>
   36     4        ASSIGN_OBJ                                               'project_id'
          5        OP_DATA                                                  !0
   37     6        ASSIGN_OBJ                                               'user_id'
          7        OP_DATA                                                  !1
   38     8        ASSIGN_OBJ                                               'type'
          9        OP_DATA                                                  !2
   39    10        ASSIGN_OBJ                                               'extra_param'
         11        OP_DATA                                                  !3
   42    12        FETCH_OBJ_R                                      ~11     'project_id'
         13        INIT_ARRAY                                       ~12     ~11, 'p'
   43    14        FETCH_OBJ_R                                      ~13     'user_id'
         15        ADD_ARRAY_ELEMENT                                ~12     ~13, 'i'
   44    16        FETCH_OBJ_R                                      ~14     'type'
         17        ADD_ARRAY_ELEMENT                                ~12     ~14, 't'
   45    18        FETCH_OBJ_R                                      ~15     'extra_param'
         19        ADD_ARRAY_ELEMENT                                ~12     ~15, 'e'
   41    20        ASSIGN                                                   !4, ~12
   48    21        INIT_FCALL                                               'http_build_query'
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !5, $17
   49    25        INIT_METHOD_CALL                                         'encrypt'
         26        SEND_VAR_EX                                              !5
         27        DO_FCALL                                      0  $19     
         28        ASSIGN                                                   !6, $19
   50    29      > RETURN                                                   !6
   51    30*     > RETURN                                                   null

End of function encryptdata

Function encrypt_data:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  encrypt_data
number of ops:  7
compiled vars:  !0 = $data, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        INIT_METHOD_CALL                                         'encrypt'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   55     5      > RETURN                                                   !1
   56     6*     > RETURN                                                   null

End of function encrypt_data

Function decrypt_data:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  decrypt_data
number of ops:  18
compiled vars:  !0 = $encrypted_text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        INIT_FCALL                                               'base64_decode'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 <array>
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                         $2      
          9        ASSIGN                                                   !0, $2
   60    10        INIT_FCALL                                               'rtrim'
         11        INIT_METHOD_CALL                                         'decrypt'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $4      
         14        SEND_VAR                                                 $4
         15        DO_ICALL                                         $5      
         16      > RETURN                                                   $5
   61    17*     > RETURN                                                   null

End of function decrypt_data

Function decryptdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  decryptData
number of ops:  20
compiled vars:  !0 = $encrypted_text, !1 = $decrypted_text, !2 = $return_decrypted_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   65     1        INIT_FCALL                                               'base64_decode'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 <array>
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !0, $4
   66    10        INIT_METHOD_CALL                                         'decrypt'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $6      
         13        ASSIGN                                                   !1, $6
   67    14        INIT_FCALL                                               'parse_str'
         15        SEND_VAR                                                 !1
         16        SEND_REF                                                 !2
         17        DO_ICALL                                                 
   68    18      > RETURN                                                   !2
   72    19*     > RETURN                                                   null

End of function decryptdata

Function decrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  decrypt
number of ops:  28
compiled vars:  !0 = $string, !1 = $iv_dec, !2 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
   77     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        FETCH_OBJ_R                                      ~3      'iv_size'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   80     8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !0
         10        FETCH_OBJ_R                                      ~6      'iv_size'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13        ASSIGN                                                   !0, $7
   83    14        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         15        FETCH_CONSTANT                                   ~9      'MCRYPT_RIJNDAEL_128'
         16        SEND_VAL_EX                                              ~9
         17        CHECK_FUNC_ARG                                           
         18        FETCH_OBJ_FUNC_ARG                               $10     'key'
         19        SEND_FUNC_ARG                                            $10
         20        SEND_VAR_EX                                              !0
         21        FETCH_CONSTANT                                   ~11     'MCRYPT_MODE_CBC'
         22        SEND_VAL_EX                                              ~11
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0  $12     
         25        ASSIGN                                                   !2, $12
   85    26      > RETURN                                                   !2
   86    27*     > RETURN                                                   null

End of function decrypt

Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQ5Z1
function name:  encrypt
number of ops:  30
compiled vars:  !0 = $string, !1 = $output, !2 = $encrypted_text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
   93     1        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
          2        FETCH_CONSTANT                                   ~3      'MCRYPT_RIJNDAEL_128'
          3        SEND_VAL_EX                                              ~3
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $4      'key'
          6        SEND_FUNC_ARG                                            $4
          7        SEND_VAR_EX                                              !0
          8        FETCH_CONSTANT                                   ~5      'MCRYPT_MODE_CBC'
          9        SEND_VAL_EX                                              ~5
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $6      'iv'
         12        SEND_FUNC_ARG                                            $6
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !1, $7
   96    15        FETCH_OBJ_R                                      ~9      'iv'
         16        CONCAT                                           ~10     ~9, !1
         17        ASSIGN                                                   !1, ~10
   99    18        INIT_FCALL                                               'base64_encode'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !1, $12
  104    22        INIT_FCALL                                               'str_replace'
         23        SEND_VAL                                                 <array>
         24        SEND_VAL                                                 <array>
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $14     
         27        ASSIGN                                                   !2, $14
  105    28      > RETURN                                                   !2
  106    29*     > RETURN                                                   null

End of function encrypt

End of class EncDec.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.16 ms | 1035 KiB | 21 Q