I am having some issues with the encryption filters http://php.net/manual/en/filters.encryption.php
The code works fine with the tripledes algorithm, however, when changing to rijndael-256 or 128, it just produces garbled data upon read.
I thought it was a error with the IV or key system, so i tried with a hardcoded pair in both read and write, however, it still produces garbled data.
public function writeEncrypt($path, $data){
$key = "1234567812345678";
$iv = "1234567812345678";
$opts = array('iv'=>$iv, 'key'=>$key, 'mode'=>'cbc');
$fp = fopen($path, 'wb');
stream_filter_append($fp, 'mcrypt.rijndael-128', STREAM_FILTER_WRITE, $opts);
fwrite($fp, $data);
fclose($fp);
return true;
}
public function readDecrypt($path){
$key = "1234567812345678";
$iv = "1234567812345678";
$opts = array('iv'=>$iv, 'key'=>$key, 'mode'=>'cbc');
$fp = fopen($path, 'rb');
stream_filter_append($fp, 'mcrypt.rijndael-128', STREAM_FILTER_READ, $opts);
$data = rtrim(stream_get_contents($fp));
fclose($fp);
header("Content-Type: application/zip");
header("Content-Length: " . count($data));
echo $data;
}
All data is input in binary form. What am i doing wrong? (No errors in the php log)
You're passing 'mcrypt.rijndael-128' instead of 'mdecrypt.rijndael-128' when trying to read the file.
Anyway, filters are really powerful and often convenient, but you shouldn't use this one in particular, as it doesn't provide authentication, which is very important in cryptography.