3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AESEncryptExampleClass { public function _encrypt($plaintext, $passphrase, $keySize, $salt, $iv, $iterationCount) { $mode = MCRYPT_MODE_CBC; //Generate AES encryption key $key = $this->_pbkdf2($passphrase, $salt, $iterationCount, $this->_parseKeyInt(MCRYPT_RIJNDAEL_128)); echo base64_encode($key) . "\n"; try { $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->_pkcs5Pad($plaintext), $mode, $iv); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } return (base64_encode($ciphertext)); } public function _getRandomBytes($length = 8) { $characters = '0123456789'; $charactersLength = strlen($characters) - 1; $bytes = ''; //Select some random characters for ($i = 0; $i < $length; $i++) { $bytes .= $characters[mt_rand(0, $charactersLength)]; } return $bytes; } private function _pbkdf2($passphrase, $salt, $iterationCount = 1000, $keyLength = MCRYPT_RIJNDAEL_128, $algorithm = 'sha1') { $hashLength = strlen( hash( $algorithm, null, true ) ); $blockCount = ceil( $keyLength / $hashLength ); $output = ''; //Create key for ( $block = 1; $block <= $blockCount; $block++ ) { //Initial hash for this block $xorsum = $last = hash_hmac( $algorithm, $salt . pack( 'N', $block ), $passphrase, true ); //Perform block iterations for ( $i = 1; $i < $iterationCount; $i++ ) { //XOR each iterate $xorsum ^= ( $last = hash_hmac( $algorithm, $last, $passphrase, true ) ); } //Append iterated block $output .= $xorsum; } //Return derived key of correct length return substr( $output, 0, $keyLength ); } private function _parseKeyInt($keySize) { $key = ""; if ($keySize == MCRYPT_RIJNDAEL_128) { $key = 16; } else if ($keySize == MCRYPT_RIJNDAEL_192) { $key = 24; } else if ($keySize == MCRYPT_RIJNDAEL_256) { $key = 32; } return $key; } private function _pkcs5Pad($text) { $blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $padding = $blockSize - (strlen($text) % $blockSize); $text .= str_repeat(chr($padding), $padding); return $text; } } /*-----------------------------------------------------------* * EXAMPLE USING AESEncryptExampleClass * *-----------------------------------------------------------*/ $iterationCount = 1000; $keySize = 128; $youmapsKey = "YOUR_YOUMAPS_KEY"; $url = "exampleURL"; //Initialize AESEncryptExampleClass $aesEncrypt = new AESEncryptExampleClass(); //Generate random IV and salt $salt = "12é4567891234567"; $iv = "1234567891234567"; //$salt = $aesEncrypt->_getRandomBytes(16); //$iv = $aesEncrypt->_getRandomBytes(16); //Encrypt the URL $encryptedURL = $aesEncrypt->_encrypt($url, $youmapsKey, $keySize, $salt, $iv, $iterationCount); echo $encryptedURL; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eC7n8
function name:  (null)
number of ops:  20
compiled vars:  !0 = $iterationCount, !1 = $keySize, !2 = $youmapsKey, !3 = $url, !4 = $aesEncrypt, !5 = $salt, !6 = $iv, !7 = $encryptedURL
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   ASSIGN                                                   !0, 1000
   87     1        ASSIGN                                                   !1, 128
   88     2        ASSIGN                                                   !2, 'YOUR_YOUMAPS_KEY'
   89     3        ASSIGN                                                   !3, 'exampleURL'
   92     4        NEW                                              $12     'AESEncryptExampleClass'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !4, $12
   95     7        ASSIGN                                                   !5, '12%C3%A94567891234567'
   96     8        ASSIGN                                                   !6, '1234567891234567'
  101     9        INIT_METHOD_CALL                                         !4, '_encrypt'
         10        SEND_VAR_EX                                              !3
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !5
         14        SEND_VAR_EX                                              !6
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0  $17     
         17        ASSIGN                                                   !7, $17
  103    18        ECHO                                                     !7
  104    19      > RETURN                                                   1

Class AESEncryptExampleClass:
Function _encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 37
Branch analysis from position: 37
2 jumps found. (Code = 107) Position 1 = 38, Position 2 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eC7n8
function name:  _encrypt
number of ops:  48
compiled vars:  !0 = $plaintext, !1 = $passphrase, !2 = $keySize, !3 = $salt, !4 = $iv, !5 = $iterationCount, !6 = $mode, !7 = $key, !8 = $ciphertext, !9 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
          5        RECV                                             !5      
    5     6        FETCH_CONSTANT                                   ~10     'MCRYPT_MODE_CBC'
          7        ASSIGN                                                   !6, ~10
    8     8        INIT_METHOD_CALL                                         '_pbkdf2'
          9        SEND_VAR_EX                                              !1
         10        SEND_VAR_EX                                              !3
         11        SEND_VAR_EX                                              !5
         12        INIT_METHOD_CALL                                         '_parseKeyInt'
         13        FETCH_CONSTANT                                   ~12     'MCRYPT_RIJNDAEL_128'
         14        SEND_VAL_EX                                              ~12
         15        DO_FCALL                                      0  $13     
         16        SEND_VAR_NO_REF_EX                                       $13
         17        DO_FCALL                                      0  $14     
         18        ASSIGN                                                   !7, $14
   10    19        INIT_FCALL                                               'base64_encode'
         20        SEND_VAR                                                 !7
         21        DO_ICALL                                         $16     
         22        CONCAT                                           ~17     $16, '%0A'
         23        ECHO                                                     ~17
   13    24        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         25        FETCH_CONSTANT                                   ~18     'MCRYPT_RIJNDAEL_128'
         26        SEND_VAL_EX                                              ~18
         27        SEND_VAR_EX                                              !7
         28        INIT_METHOD_CALL                                         '_pkcs5Pad'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0  $19     
         31        SEND_VAR_NO_REF_EX                                       $19
         32        SEND_VAR_EX                                              !6
         33        SEND_VAR_EX                                              !4
         34        DO_FCALL                                      0  $20     
         35        ASSIGN                                                   !8, $20
         36      > JMP                                                      ->43
   15    37  E > > CATCH                                       last         'Exception'
   16    38    >   ECHO                                                     'Caught+exception%3A+'
         39        INIT_METHOD_CALL                                         !9, 'getMessage'
         40        DO_FCALL                                      0  $22     
         41        ECHO                                                     $22
         42        ECHO                                                     '%0A'
   19    43    >   INIT_FCALL                                               'base64_encode'
         44        SEND_VAR                                                 !8
         45        DO_ICALL                                         $23     
         46      > RETURN                                                   $23
   20    47*     > RETURN                                                   null

End of function _encrypt

Function _getrandombytes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 8
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/eC7n8
function name:  _getRandomBytes
number of ops:  19
compiled vars:  !0 = $length, !1 = $characters, !2 = $charactersLength, !3 = $bytes, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                        !0      8
   23     1        ASSIGN                                                   !1, '0123456789'
   24     2        STRLEN                                           ~6      !1
          3        SUB                                              ~7      ~6, 1
          4        ASSIGN                                                   !2, ~7
   25     5        ASSIGN                                                   !3, ''
   28     6        ASSIGN                                                   !4, 0
          7      > JMP                                                      ->15
   29     8    >   INIT_FCALL                                               'mt_rand'
          9        SEND_VAL                                                 0
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $11     
         12        FETCH_DIM_R                                      ~12     !1, $11
         13        ASSIGN_OP                                     8          !3, ~12
   28    14        PRE_INC                                                  !4
         15    >   IS_SMALLER                                               !4, !0
         16      > JMPNZ                                                    ~15, ->8
   32    17    > > RETURN                                                   !3
   33    18*     > RETURN                                                   null

End of function _getrandombytes

Function _pbkdf2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 20
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 35
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 20
Branch analysis from position: 50
Branch analysis from position: 20
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 35
Branch analysis from position: 46
Branch analysis from position: 35
filename:       /in/eC7n8
function name:  _pbkdf2
number of ops:  57
compiled vars:  !0 = $passphrase, !1 = $salt, !2 = $iterationCount, !3 = $keyLength, !4 = $algorithm, !5 = $hashLength, !6 = $blockCount, !7 = $output, !8 = $block, !9 = $xorsum, !10 = $last, !11 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      1000
          3        RECV_INIT                                        !3      <const ast>
          4        RECV_INIT                                        !4      'sha1'
   36     5        INIT_FCALL                                               'hash'
          6        SEND_VAR                                                 !4
          7        SEND_VAL                                                 null
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $12     
         10        STRLEN                                           ~13     $12
         11        ASSIGN                                                   !5, ~13
   37    12        INIT_FCALL                                               'ceil'
         13        DIV                                              ~15     !3, !5
         14        SEND_VAL                                                 ~15
         15        DO_ICALL                                         $16     
         16        ASSIGN                                                   !6, $16
   38    17        ASSIGN                                                   !7, ''
   41    18        ASSIGN                                                   !8, 1
         19      > JMP                                                      ->48
   43    20    >   INIT_FCALL                                               'hash_hmac'
         21        SEND_VAR                                                 !4
         22        INIT_FCALL                                               'pack'
         23        SEND_VAL                                                 'N'
         24        SEND_VAR                                                 !8
         25        DO_ICALL                                         $20     
         26        CONCAT                                           ~21     !1, $20
         27        SEND_VAL                                                 ~21
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $22     
         31        ASSIGN                                           ~23     !10, $22
         32        ASSIGN                                                   !9, ~23
   46    33        ASSIGN                                                   !11, 1
         34      > JMP                                                      ->44
   48    35    >   INIT_FCALL                                               'hash_hmac'
         36        SEND_VAR                                                 !4
         37        SEND_VAR                                                 !10
         38        SEND_VAR                                                 !0
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $26     
         41        ASSIGN                                           ~27     !10, $26
         42        ASSIGN_OP                                    11          !9, ~27
   46    43        PRE_INC                                                  !11
         44    >   IS_SMALLER                                               !11, !2
         45      > JMPNZ                                                    ~30, ->35
   52    46    >   ASSIGN_OP                                     8          !7, !9
   41    47        PRE_INC                                                  !8
         48    >   IS_SMALLER_OR_EQUAL                                      !8, !6
         49      > JMPNZ                                                    ~33, ->20
   56    50    >   INIT_FCALL                                               'substr'
         51        SEND_VAR                                                 !7
         52        SEND_VAL                                                 0
         53        SEND_VAR                                                 !3
         54        DO_ICALL                                         $34     
         55      > RETURN                                                   $34
   57    56*     > RETURN                                                   null

End of function _pbkdf2

Function _parsekeyint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/eC7n8
function name:  _parseKeyInt
number of ops:  18
compiled vars:  !0 = $keySize, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   60     1        ASSIGN                                                   !1, ''
   61     2        FETCH_CONSTANT                                   ~3      'MCRYPT_RIJNDAEL_128'
          3        IS_EQUAL                                                 !0, ~3
          4      > JMPZ                                                     ~4, ->7
   62     5    >   ASSIGN                                                   !1, 16
          6      > JMP                                                      ->16
   64     7    >   FETCH_CONSTANT                                   ~6      'MCRYPT_RIJNDAEL_192'
          8        IS_EQUAL                                                 !0, ~6
          9      > JMPZ                                                     ~7, ->12
   65    10    >   ASSIGN                                                   !1, 24
         11      > JMP                                                      ->16
   67    12    >   FETCH_CONSTANT                                   ~9      'MCRYPT_RIJNDAEL_256'
         13        IS_EQUAL                                                 !0, ~9
         14      > JMPZ                                                     ~10, ->16
   68    15    >   ASSIGN                                                   !1, 32
   70    16    > > RETURN                                                   !1
   71    17*     > RETURN                                                   null

End of function _parsekeyint

Function _pkcs5pad:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eC7n8
function name:  _pkcs5Pad
number of ops:  22
compiled vars:  !0 = $text, !1 = $blockSize, !2 = $padding
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   74     1        INIT_FCALL_BY_NAME                                       'mcrypt_get_block_size'
          2        FETCH_CONSTANT                                   ~3      'MCRYPT_RIJNDAEL_128'
          3        SEND_VAL_EX                                              ~3
          4        FETCH_CONSTANT                                   ~4      'MCRYPT_MODE_CBC'
          5        SEND_VAL_EX                                              ~4
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !1, $5
   75     8        STRLEN                                           ~7      !0
          9        MOD                                              ~8      ~7, !1
         10        SUB                                              ~9      !1, ~8
         11        ASSIGN                                                   !2, ~9
   76    12        INIT_FCALL                                               'str_repeat'
         13        INIT_FCALL                                               'chr'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $11     
         16        SEND_VAR                                                 $11
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $12     
         19        ASSIGN_OP                                     8          !0, $12
   77    20      > RETURN                                                   !0
   78    21*     > RETURN                                                   null

End of function _pkcs5pad

End of class AESEncryptExampleClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.69 ms | 1412 KiB | 31 Q