3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key = "myKeyIs"; protected $iv_size; protected $iv; public function __construct(){ $this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); } public function encryptData($input) { $input = $input; $output = $this->encrypt($input); return $output; } public function decryptData($input) { $input = $input; $output = $this->decrypt($input); return $output; } public function decrypt($string) { $string = base64_decode($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) { $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); return $output; } } $test = new Encryption(); $encrypted = $test->encryptData("Vicky"); echo $encrypted."\n"; echo $test->decryptData($encrypted);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EVLkr
function name:  (null)
number of ops:  21
compiled vars:  !0 = $test, !1 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                                 
    4     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 1
          6        DO_ICALL                                                 
   59     7        NEW                                              $4      'Encryption'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $4
   60    10        INIT_METHOD_CALL                                         !0, 'encryptData'
         11        SEND_VAL_EX                                              'Vicky'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !1, $7
   61    14        CONCAT                                           ~9      !1, '%0A'
         15        ECHO                                                     ~9
   62    16        INIT_METHOD_CALL                                         !0, 'decryptData'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $10     
         19        ECHO                                                     $10
         20      > RETURN                                                   1

Class Encryption:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EVLkr
function name:  __construct
number of ops:  16
compiled vars:  !0 = $iv_size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
          1        FETCH_CONSTANT                                   ~2      'MCRYPT_RIJNDAEL_128'
          2        SEND_VAL_EX                                              ~2
          3        FETCH_CONSTANT                                   ~3      'MCRYPT_MODE_CBC'
          4        SEND_VAL_EX                                              ~3
          5        DO_FCALL                                      0  $4      
          6        ASSIGN_OBJ                                               'iv_size'
          7        OP_DATA                                                  $4
   14     8        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
          9        SEND_VAR_EX                                              !0
         10        FETCH_CONSTANT                                   ~6      'MCRYPT_RAND'
         11        SEND_VAL_EX                                              ~6
         12        DO_FCALL                                      0  $7      
         13        ASSIGN_OBJ                                               'iv'
         14        OP_DATA                                                  $7
   15    15      > 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/EVLkr
function name:  encryptData
number of ops:  8
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !0, !0
   19     2        INIT_METHOD_CALL                                         'encrypt'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   20     6      > RETURN                                                   !1
   21     7*     > RETURN                                                   null

End of function encryptdata

Function decryptdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EVLkr
function name:  decryptData
number of ops:  8
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        ASSIGN                                                   !0, !0
   25     2        INIT_METHOD_CALL                                         'decrypt'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   26     6      > RETURN                                                   !1
   27     7*     > 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/EVLkr
function name:  decrypt
number of ops:  32
compiled vars:  !0 = $string, !1 = $iv_dec, !2 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'base64_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   32     5        INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 0
          8        FETCH_OBJ_R                                      ~5      'iv_size'
          9        SEND_VAL                                                 ~5
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !1, $6
   35    12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        FETCH_OBJ_R                                      ~8      'iv_size'
         15        SEND_VAL                                                 ~8
         16        DO_ICALL                                         $9      
         17        ASSIGN                                                   !0, $9
   38    18        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         19        FETCH_CONSTANT                                   ~11     'MCRYPT_RIJNDAEL_128'
         20        SEND_VAL_EX                                              ~11
         21        CHECK_FUNC_ARG                                           
         22        FETCH_OBJ_FUNC_ARG                               $12     'key'
         23        SEND_FUNC_ARG                                            $12
         24        SEND_VAR_EX                                              !0
   39    25        FETCH_CONSTANT                                   ~13     'MCRYPT_MODE_CBC'
         26        SEND_VAL_EX                                              ~13
   38    27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0  $14     
         29        ASSIGN                                                   !2, $14
   40    30      > RETURN                                                   !2
   41    31*     > 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/EVLkr
function name:  encrypt
number of ops:  24
compiled vars:  !0 = $string, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
          2        FETCH_CONSTANT                                   ~2      'MCRYPT_RIJNDAEL_128'
          3        SEND_VAL_EX                                              ~2
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $3      'key'
          6        SEND_FUNC_ARG                                            $3
          7        SEND_VAR_EX                                              !0
   46     8        FETCH_CONSTANT                                   ~4      'MCRYPT_MODE_CBC'
          9        SEND_VAL_EX                                              ~4
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $5      'iv'
         12        SEND_FUNC_ARG                                            $5
         13        DO_FCALL                                      0  $6      
   45    14        ASSIGN                                                   !1, $6
   49    15        FETCH_OBJ_R                                      ~8      'iv'
         16        CONCAT                                           ~9      ~8, !1
         17        ASSIGN                                                   !1, ~9
   52    18        INIT_FCALL                                               'base64_encode'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !1, $11
   54    22      > RETURN                                                   !1
   55    23*     > RETURN                                                   null

End of function encrypt

End of class Encryption.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.68 ms | 1396 KiB | 23 Q