3v4l.org

run code in 300+ PHP versions simultaneously
<?php # --- ENCRYPTION --- # the key should be random binary, use scrypt, bcrypt or PBKDF2 to # convert a string into a key # key is specified using hexadecimal $key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); # show key size use either 16, 24 or 32 byte keys for AES-128, 192 # and 256 respectively $key_size = strlen($key); echo "Key size: " . $key_size . "\n"; $plaintext = "This string was AES-256 / CBC / ZeroBytePadding encrypted."; # create a random IV to use with CBC encoding $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); # 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) $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $iv); # prepend the IV for it to be available for decryption $ciphertext = $iv . $ciphertext; # encode the resulting cipher text so it can be represented by a string $ciphertext_base64 = base64_encode($ciphertext); echo $ciphertext_base64 . "\n"; # === WARNING === # Resulting cipher text has no integrity or authenticity added # and is not protected against padding oracle attacks. # --- DECRYPTION --- $ciphertext_dec = base64_decode($ciphertext_base64); # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($ciphertext_dec, 0, $iv_size); # retrieves the cipher text (everything except the $iv_size in the front) $ciphertext_dec = substr($ciphertext_dec, $iv_size); # may remove 00h valued characters from end of plain text $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); echo $plaintext_dec . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZNXtf
function name:  (null)
number of ops:  70
compiled vars:  !0 = $key, !1 = $key_size, !2 = $plaintext, !3 = $iv_size, !4 = $iv, !5 = $ciphertext, !6 = $ciphertext_base64, !7 = $ciphertext_dec, !8 = $iv_dec, !9 = $plaintext_dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'pack'
          1        SEND_VAL                                                 'H%2A'
          2        SEND_VAL                                                 'bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3'
          3        DO_ICALL                                         $10     
          4        ASSIGN                                                   !0, $10
   12     5        STRLEN                                           ~12     !0
          6        ASSIGN                                                   !1, ~12
   13     7        CONCAT                                           ~14     'Key+size%3A+', !1
          8        CONCAT                                           ~15     ~14, '%0A'
          9        ECHO                                                     ~15
   15    10        ASSIGN                                                   !2, 'This+string+was+AES-256+%2F+CBC+%2F+ZeroBytePadding+encrypted.'
   18    11        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
         12        FETCH_CONSTANT                                   ~17     'MCRYPT_RIJNDAEL_128'
         13        SEND_VAL_EX                                              ~17
         14        FETCH_CONSTANT                                   ~18     'MCRYPT_MODE_CBC'
         15        SEND_VAL_EX                                              ~18
         16        DO_FCALL                                      0  $19     
         17        ASSIGN                                                   !3, $19
   19    18        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         19        SEND_VAR_EX                                              !3
         20        FETCH_CONSTANT                                   ~21     'MCRYPT_RAND'
         21        SEND_VAL_EX                                              ~21
         22        DO_FCALL                                      0  $22     
         23        ASSIGN                                                   !4, $22
   25    24        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         25        FETCH_CONSTANT                                   ~24     'MCRYPT_RIJNDAEL_128'
         26        SEND_VAL_EX                                              ~24
         27        SEND_VAR_EX                                              !0
         28        SEND_VAR_EX                                              !2
   26    29        FETCH_CONSTANT                                   ~25     'MCRYPT_MODE_CBC'
         30        SEND_VAL_EX                                              ~25
   25    31        SEND_VAR_EX                                              !4
         32        DO_FCALL                                      0  $26     
         33        ASSIGN                                                   !5, $26
   29    34        CONCAT                                           ~28     !4, !5
         35        ASSIGN                                                   !5, ~28
   32    36        INIT_FCALL                                               'base64_encode'
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                         $30     
         39        ASSIGN                                                   !6, $30
   34    40        CONCAT                                           ~32     !6, '%0A'
         41        ECHO                                                     ~32
   43    42        INIT_FCALL                                               'base64_decode'
         43        SEND_VAR                                                 !6
         44        DO_ICALL                                         $33     
         45        ASSIGN                                                   !7, $33
   46    46        INIT_FCALL                                               'substr'
         47        SEND_VAR                                                 !7
         48        SEND_VAL                                                 0
         49        SEND_VAR                                                 !3
         50        DO_ICALL                                         $35     
         51        ASSIGN                                                   !8, $35
   49    52        INIT_FCALL                                               'substr'
         53        SEND_VAR                                                 !7
         54        SEND_VAR                                                 !3
         55        DO_ICALL                                         $37     
         56        ASSIGN                                                   !7, $37
   52    57        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         58        FETCH_CONSTANT                                   ~39     'MCRYPT_RIJNDAEL_128'
         59        SEND_VAL_EX                                              ~39
         60        SEND_VAR_EX                                              !0
         61        SEND_VAR_EX                                              !7
   53    62        FETCH_CONSTANT                                   ~40     'MCRYPT_MODE_CBC'
         63        SEND_VAL_EX                                              ~40
   52    64        SEND_VAR_EX                                              !8
         65        DO_FCALL                                      0  $41     
         66        ASSIGN                                                   !9, $41
   55    67        CONCAT                                           ~43     !9, '%0A'
         68        ECHO                                                     ~43
         69      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.67 ms | 1400 KiB | 21 Q