Fix: add length of data for cleanly remove padding
This commit is contained in:
parent
3ef86dedec
commit
65c5f337a9
@ -248,9 +248,13 @@ print_r($xfss[$this->cipher]);
|
|||||||
// return false if unable to open file
|
// return false if unable to open file
|
||||||
$msg = "encrypt_file: cannot open ".$dst_filename." ";
|
$msg = "encrypt_file: cannot open ".$dst_filename." ";
|
||||||
if (!$dest_fp) trigger_error($msg, E_USER_ERROR);
|
if (!$dest_fp) trigger_error($msg, E_USER_ERROR);
|
||||||
|
|
||||||
|
// adds length of content for cleanly removing the padding
|
||||||
|
$length = strlen($filecontents);
|
||||||
|
$cleanfilecontents = $length.'|'.$filecontents;
|
||||||
|
|
||||||
// write encrypted data to file
|
// write encrypted data to file
|
||||||
fwrite($dest_fp, $this->encrypt($filecontents));
|
fwrite($dest_fp, $this->encrypt($cleanfilecontents));
|
||||||
|
|
||||||
// close encrypted file pointer
|
// close encrypted file pointer
|
||||||
fclose($dest_fp);
|
fclose($dest_fp);
|
||||||
@ -302,6 +306,10 @@ print_r($xfss[$this->cipher]);
|
|||||||
|
|
||||||
// decrypt file contents
|
// decrypt file contents
|
||||||
$contents = $this->decrypt($contents);
|
$contents = $this->decrypt($contents);
|
||||||
|
|
||||||
|
// remove the padding
|
||||||
|
list($length, $padded_data) = explode('|', $contents, 2);
|
||||||
|
$contents = substr($padded_data, 0, $length);
|
||||||
|
|
||||||
// make sure contents where not modified
|
// make sure contents where not modified
|
||||||
if( $this->efc['crc'] != $this->CRC16HexDigest($contents))
|
if( $this->efc['crc'] != $this->CRC16HexDigest($contents))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user