3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Define a 32-byte (64 character) hexadecimal encryption key // Note: The same encryption key used to encrypt the data must be used to decrypt the data define('ENCRYPTION_KEY', 'zEFnGVANrtEUTMLVyBusu4pqpHjqhn3X+cCtepGKg89VgIi6KugA+hITeeKIpnQIQM8UZbUkRpuCe/d8Rf5HFQJSawpeHoUg5NtcGam0eeTw+1bnFPT3dcPNB8IekPBDyXTyV44s3yaYMUAXZWthWHEVDFfKSjfTpPmQkB8fp6Go/qytRtiP3LyYmofhOOOV8APh0Pv34VPjCtxcJUpqIw=='); // Encrypt Function function mc_encrypt($encrypt, $key){ $encrypt = serialize($encrypt); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM); $key = pack('H*', $key); $mac = hash_hmac('sha256', $encrypt, substr(bin2hex($key), -32)); $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt.$mac, MCRYPT_MODE_CBC, $iv); $encoded = base64_encode($passcrypt).'|'.base64_encode($iv); return $encoded; } // Decrypt Function function mc_decrypt($decrypt, $key){ $decrypt = explode('|', $decrypt.'|'); $decoded = base64_decode($decrypt[0]); $iv = base64_decode($decrypt[1]); if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)){ return false; } $key = pack('H*', $key); $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv)); $mac = substr($decrypted, -64); $decrypted = substr($decrypted, 0, -64); $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32)); if($calcmac!==$mac){ return false; } $decrypted = unserialize($decrypted); return $decrypted; } echo '<h1>Rijndael 256-bit CBC Encryption Function</h1>'; $data = 'G+glEae6W/1XjA7vRm21nNyEco/c+J2TdR0Qp8dcjPK/ZEJpSw8lYr3+NDY3VpFZK/PMVHnhLmbzHIY7GAR1bVcy3Ix3D2Q5cVi8F6bmY='; $encrypted_data = mc_encrypt($data, ENCRYPTION_KEY); echo '<h2>Example #1: String Data</h2>'; echo 'Data to be Encrypted: ' . $data . '<br/>'; echo 'Encrypted Data: ' . $encrypted_data . '<br/>'; echo 'Decrypted Data: ' . mc_decrypt($encrypted_data, ENCRYPTION_KEY) . '</br>'; $data = array(1, 5, 8, 9, 22, 10, 61); $encrypted_data = mc_encrypt($data, ENCRYPTION_KEY); echo '<h2>Example #2: Non-String Data</h2>'; echo 'Data to be Encrypted: <pre>'; print_r($data); echo '</pre><br/>'; echo 'Encrypted Data: ' . $encrypted_data . '<br/>'; echo 'Decrypted Data: <pre>'; print_r(mc_decrypt($encrypted_data, ENCRYPTION_KEY)); echo '</pre>'; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CcnCb
function name:  (null)
number of ops:  54
compiled vars:  !0 = $data, !1 = $encrypted_data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'ENCRYPTION_KEY'
          2        SEND_VAL                                                     'zEFnGVANrtEUTMLVyBusu4pqpHjqhn3X%2BcCtepGKg89VgIi6KugA%2BhITeeKIpnQIQM8UZbUkRpuCe%2Fd8Rf5HFQJSawpeHoUg5NtcGam0eeTw%2B1bnFPT3dcPNB8IekPBDyXTyV44s3yaYMUAXZWthWHEVDFfKSjfTpPmQkB8fp6Go%2FqytRtiP3LyYmofhOOOV8APh0Pv34VPjCtxcJUpqIw%3D%3D'
          3        DO_ICALL                                                     
   30     4        ECHO                                                         '%3Ch1%3ERijndael+256-bit+CBC+Encryption+Function%3C%2Fh1%3E'
   31     5        ASSIGN                                                       !0, 'G%2BglEae6W%2F1XjA7vRm21nNyEco%2Fc%2BJ2TdR0Qp8dcjPK%2FZEJpSw8lYr3%2BNDY3VpFZK%2FPMVHnhLmbzHIY7GAR1bVcy3Ix3D2Q5cVi8F6bmY%3D'
   32     6        INIT_FCALL                                                   'mc_encrypt'
          7        SEND_VAR                                                     !0
          8        FETCH_CONSTANT                                       ~4      'ENCRYPTION_KEY'
          9        SEND_VAL                                                     ~4
         10        DO_FCALL                                          0  $5      
         11        ASSIGN                                                       !1, $5
   33    12        ECHO                                                         '%3Ch2%3EExample+%231%3A+String+Data%3C%2Fh2%3E'
   34    13        CONCAT                                               ~7      'Data+to+be+Encrypted%3A+', !0
         14        CONCAT                                               ~8      ~7, '%3Cbr%2F%3E'
         15        ECHO                                                         ~8
   35    16        CONCAT                                               ~9      'Encrypted+Data%3A+', !1
         17        CONCAT                                               ~10     ~9, '%3Cbr%2F%3E'
         18        ECHO                                                         ~10
   36    19        INIT_FCALL                                                   'mc_decrypt'
         20        SEND_VAR                                                     !1
         21        FETCH_CONSTANT                                       ~11     'ENCRYPTION_KEY'
         22        SEND_VAL                                                     ~11
         23        DO_FCALL                                          0  $12     
         24        CONCAT                                               ~13     'Decrypted+Data%3A+', $12
         25        CONCAT                                               ~14     ~13, '%3C%2Fbr%3E'
         26        ECHO                                                         ~14
   37    27        ASSIGN                                                       !0, <array>
   38    28        INIT_FCALL                                                   'mc_encrypt'
         29        SEND_VAR                                                     !0
         30        FETCH_CONSTANT                                       ~16     'ENCRYPTION_KEY'
         31        SEND_VAL                                                     ~16
         32        DO_FCALL                                          0  $17     
         33        ASSIGN                                                       !1, $17
   39    34        ECHO                                                         '%3Ch2%3EExample+%232%3A+Non-String+Data%3C%2Fh2%3E'
   40    35        ECHO                                                         'Data+to+be+Encrypted%3A+%3Cpre%3E'
   41    36        INIT_FCALL                                                   'print_r'
         37        SEND_VAR                                                     !0
         38        DO_ICALL                                                     
   42    39        ECHO                                                         '%3C%2Fpre%3E%3Cbr%2F%3E'
   43    40        CONCAT                                               ~20     'Encrypted+Data%3A+', !1
         41        CONCAT                                               ~21     ~20, '%3Cbr%2F%3E'
         42        ECHO                                                         ~21
   44    43        ECHO                                                         'Decrypted+Data%3A+%3Cpre%3E'
   45    44        INIT_FCALL                                                   'print_r'
         45        INIT_FCALL                                                   'mc_decrypt'
         46        SEND_VAR                                                     !1
         47        FETCH_CONSTANT                                       ~22     'ENCRYPTION_KEY'
         48        SEND_VAL                                                     ~22
         49        DO_FCALL                                          0  $23     
         50        SEND_VAR                                                     $23
         51        DO_ICALL                                                     
   46    52        ECHO                                                         '%3C%2Fpre%3E'
   47    53      > RETURN                                                       1

Function mc_encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CcnCb
function name:  mc_encrypt
number of ops:  55
compiled vars:  !0 = $encrypt, !1 = $key, !2 = $iv, !3 = $mac, !4 = $passcrypt, !5 = $encoded
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    7     2        INIT_FCALL                                                   'serialize'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $6      
          5        ASSIGN                                                       !0, $6
    8     6        INIT_FCALL_BY_NAME                                           'mcrypt_create_iv'
          7        INIT_FCALL_BY_NAME                                           'mcrypt_get_iv_size'
          8        FETCH_CONSTANT                                       ~8      'MCRYPT_RIJNDAEL_256'
          9        SEND_VAL_EX                                                  ~8
         10        FETCH_CONSTANT                                       ~9      'MCRYPT_MODE_CBC'
         11        SEND_VAL_EX                                                  ~9
         12        DO_FCALL                                          0  $10     
         13        SEND_VAR_NO_REF_EX                                           $10
         14        FETCH_CONSTANT                                       ~11     'MCRYPT_DEV_URANDOM'
         15        SEND_VAL_EX                                                  ~11
         16        DO_FCALL                                          0  $12     
         17        ASSIGN                                                       !2, $12
    9    18        INIT_FCALL                                                   'pack'
         19        SEND_VAL                                                     'H%2A'
         20        SEND_VAR                                                     !1
         21        DO_ICALL                                             $14     
         22        ASSIGN                                                       !1, $14
   10    23        INIT_FCALL                                                   'hash_hmac'
         24        SEND_VAL                                                     'sha256'
         25        SEND_VAR                                                     !0
         26        INIT_FCALL                                                   'bin2hex'
         27        SEND_VAR                                                     !1
         28        DO_ICALL                                             $16     
         29        FRAMELESS_ICALL_2                substr              ~17     $16, -32
         30        SEND_VAL                                                     ~17
         31        DO_ICALL                                             $18     
         32        ASSIGN                                                       !3, $18
   11    33        INIT_FCALL_BY_NAME                                           'mcrypt_encrypt'
         34        FETCH_CONSTANT                                       ~20     'MCRYPT_RIJNDAEL_256'
         35        SEND_VAL_EX                                                  ~20
         36        SEND_VAR_EX                                                  !1
         37        CONCAT                                               ~21     !0, !3
         38        SEND_VAL_EX                                                  ~21
         39        FETCH_CONSTANT                                       ~22     'MCRYPT_MODE_CBC'
         40        SEND_VAL_EX                                                  ~22
         41        SEND_VAR_EX                                                  !2
         42        DO_FCALL                                          0  $23     
         43        ASSIGN                                                       !4, $23
   12    44        INIT_FCALL                                                   'base64_encode'
         45        SEND_VAR                                                     !4
         46        DO_ICALL                                             $25     
         47        CONCAT                                               ~26     $25, '%7C'
         48        INIT_FCALL                                                   'base64_encode'
         49        SEND_VAR                                                     !2
         50        DO_ICALL                                             $27     
         51        CONCAT                                               ~28     ~26, $27
         52        ASSIGN                                                       !5, ~28
   13    53      > RETURN                                                       !5
   14    54*     > RETURN                                                       null

End of function mc_encrypt

Function mc_decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CcnCb
function name:  mc_decrypt
number of ops:  68
compiled vars:  !0 = $decrypt, !1 = $key, !2 = $decoded, !3 = $iv, !4 = $decrypted, !5 = $mac, !6 = $calcmac
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   17     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '%7C'
          4        CONCAT                                               ~7      !0, '%7C'
          5        SEND_VAL                                                     ~7
          6        DO_ICALL                                             $8      
          7        ASSIGN                                                       !0, $8
   18     8        INIT_FCALL                                                   'base64_decode'
          9        FETCH_DIM_R                                          ~10     !0, 0
         10        SEND_VAL                                                     ~10
         11        DO_ICALL                                             $11     
         12        ASSIGN                                                       !2, $11
   19    13        INIT_FCALL                                                   'base64_decode'
         14        FETCH_DIM_R                                          ~13     !0, 1
         15        SEND_VAL                                                     ~13
         16        DO_ICALL                                             $14     
         17        ASSIGN                                                       !3, $14
   20    18        STRLEN                                               ~16     !3
         19        INIT_FCALL_BY_NAME                                           'mcrypt_get_iv_size'
         20        FETCH_CONSTANT                                       ~17     'MCRYPT_RIJNDAEL_256'
         21        SEND_VAL_EX                                                  ~17
         22        FETCH_CONSTANT                                       ~18     'MCRYPT_MODE_CBC'
         23        SEND_VAL_EX                                                  ~18
         24        DO_FCALL                                          0  $19     
         25        IS_NOT_IDENTICAL                                             $19, ~16
         26      > JMPZ                                                         ~20, ->28
         27    > > RETURN                                                       <false>
   21    28    >   INIT_FCALL                                                   'pack'
         29        SEND_VAL                                                     'H%2A'
         30        SEND_VAR                                                     !1
         31        DO_ICALL                                             $21     
         32        ASSIGN                                                       !1, $21
   22    33        INIT_FCALL_BY_NAME                                           'mcrypt_decrypt'
         34        FETCH_CONSTANT                                       ~23     'MCRYPT_RIJNDAEL_256'
         35        SEND_VAL_EX                                                  ~23
         36        SEND_VAR_EX                                                  !1
         37        SEND_VAR_EX                                                  !2
         38        FETCH_CONSTANT                                       ~24     'MCRYPT_MODE_CBC'
         39        SEND_VAL_EX                                                  ~24
         40        SEND_VAR_EX                                                  !3
         41        DO_FCALL                                          0  $25     
         42        FRAMELESS_ICALL_1                trim                ~26     $25
         43        ASSIGN                                                       !4, ~26
   23    44        FRAMELESS_ICALL_2                substr              ~28     !4, -64
         45        ASSIGN                                                       !5, ~28
   24    46        FRAMELESS_ICALL_3                substr              ~30     !4, 0
         47        OP_DATA                                                      -64
         48        ASSIGN                                                       !4, ~30
   25    49        INIT_FCALL                                                   'hash_hmac'
         50        SEND_VAL                                                     'sha256'
         51        SEND_VAR                                                     !4
         52        INIT_FCALL                                                   'bin2hex'
         53        SEND_VAR                                                     !1
         54        DO_ICALL                                             $32     
         55        FRAMELESS_ICALL_2                substr              ~33     $32, -32
         56        SEND_VAL                                                     ~33
         57        DO_ICALL                                             $34     
         58        ASSIGN                                                       !6, $34
   26    59        IS_NOT_IDENTICAL                                             !6, !5
         60      > JMPZ                                                         ~36, ->62
         61    > > RETURN                                                       <false>
   27    62    >   INIT_FCALL                                                   'unserialize'
         63        SEND_VAR                                                     !4
         64        DO_ICALL                                             $37     
         65        ASSIGN                                                       !4, $37
   28    66      > RETURN                                                       !4
   29    67*     > RETURN                                                       null

End of function mc_decrypt

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
155.38 ms | 2708 KiB | 27 Q