嗨,我正在尝试编写代码来上传 pdf 文件,然后将其通过 ftp 传输到 NAS 盒,然后允许用户查看文档 - 即反向通过 ftp 从 nas 获取文档。一切都很好。但是我现在需要加密 NAs 盒子上的数据。我阅读了有关过滤器的信息但我无法使其工作我所看到的唯一内容是文本。我现在到的地方是:
发送代码
$passphrase = 'My secret';
/* Turn a human readable passphrase
* into a reproducable iv/key pair
*/
$iv = substr(md5('iv'.$passphrase, true), 0, 8);
$key = substr(md5('pass1'.$passphrase, true) .
md5('pass2'.$passphrase, true), 0, 24);
$opts = array('iv'=>$iv, 'key'=>$key);
$fp = fopen($file, 'wb');//$file is tne uploaded file
stream_filter_append($fp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
fwrite($fp, 'Secret secret secret data');// I know this bit is wrong!!
fclose($fp);
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
//echo "successfully uploaded $file\n";
所以我在评论中改变了它
$passphrase = 'My secret';
/* Turn a human readable passphrase
* into a reproducable iv/key pair
*/
$iv = substr(md5('iv'.$passphrase, true), 0, 8);
$key = substr(md5('pass1'.$passphrase, true) .
md5('pass2'.$passphrase, true), 0, 24);
$opts = array('iv'=>$iv, 'key'=>$key);
$fp = fopen($file, 'wb');
$fplocal = fopen("templocal.PDF", 'wb');
stream_filter_append($fplocal, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
fwrite($fplocal, $fp);
fclose($fplocal);
fclose($fp);
// try to upload $file
if (ftp_put($conn_id, $remote_file, $fplocal,
但它不起作用 - 我做错了什么吗?