3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key; protected $iv_size; protected $iv; public function __construct(){ $this->key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); $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) { $output = $this->encrypt($input); return $output; } public function decryptData($input) { $output = $this->decrypt($input); return $output; } protected 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; } protected 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/8gbkM
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                                                 
   58     7        NEW                                              $4      'Encryption'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $4
   59    10        INIT_METHOD_CALL                                         !0, 'encryptData'
         11        SEND_VAL_EX                                              'Vicky'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !1, $7
   60    14        CONCAT                                           ~9      !1, '%0A'
         15        ECHO                                                     ~9
   61    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/8gbkM
function name:  __construct
number of ops:  22
compiled vars:  !0 = $iv_size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'pack'
          1        SEND_VAL                                                 'H%2A'
          2        SEND_VAL                                                 'bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3'
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               'key'
          5        OP_DATA                                                  $2
   14     6        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
          7        FETCH_CONSTANT                                   ~4      'MCRYPT_RIJNDAEL_128'
          8        SEND_VAL_EX                                              ~4
          9        FETCH_CONSTANT                                   ~5      'MCRYPT_MODE_CBC'
         10        SEND_VAL_EX                                              ~5
         11        DO_FCALL                                      0  $6      
         12        ASSIGN_OBJ                                               'iv_size'
         13        OP_DATA                                                  $6
   15    14        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         15        SEND_VAR_EX                                              !0
         16        FETCH_CONSTANT                                   ~8      'MCRYPT_RAND'
         17        SEND_VAL_EX                                              ~8
         18        DO_FCALL                                      0  $9      
         19        ASSIGN_OBJ                                               'iv'
         20        OP_DATA                                                  $9
   16    21      > 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/8gbkM
function name:  encryptData
number of ops:  7
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_METHOD_CALL                                         'encrypt'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   20     5      > RETURN                                                   !1
   21     6*     > 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/8gbkM
function name:  decryptData
number of ops:  7
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         'decrypt'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   25     5      > RETURN                                                   !1
   26     6*     > 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/8gbkM
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
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'base64_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   31     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
   34    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
   37    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
   38    25        FETCH_CONSTANT                                   ~13     'MCRYPT_MODE_CBC'
         26        SEND_VAL_EX                                              ~13
   37    27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0  $14     
         29        ASSIGN                                                   !2, $14
   39    30      > RETURN                                                   !2
   40    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/8gbkM
function name:  encrypt
number of ops:  24
compiled vars:  !0 = $string, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     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
   45     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      
   44    14        ASSIGN                                                   !1, $6
   48    15        FETCH_OBJ_R                                      ~8      'iv'
         16        CONCAT                                           ~9      ~8, !1
         17        ASSIGN                                                   !1, ~9
   51    18        INIT_FCALL                                               'base64_encode'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !1, $11
   53    22      > RETURN                                                   !1
   54    23*     > RETURN                                                   null

End of function encrypt

End of class Encryption.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.76 ms | 1404 KiB | 25 Q