您好我正在尝试编写上传pdf文件的代码,然后将其ftps到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,
但它不起作用 - 我做错了吗?
答案 0 :(得分:0)
$fplocal = fopen("templocal.PDF", 'wb');
stream_filter_append($fplocal, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
fwrite($fplocal, file_get_contents($file));
fclose($fplocal);
评论问题 已编辑
<?php
// Crypt parameters
$passphrase = 'thisIsThePassphrase';
$iv = substr(
md5('iv'.$passphrase, true)
, 0, 8
);
$key = substr(
md5('pad1'.$passphrase, true) .
md5('pad2'.$passphrase, true)
, 0, 24
);
$opts = array('iv'=>$iv, 'key'=>$key);
// Input file crypt to outputFile
$outputFile = fopen("outputFileToWrite.PDF", "wb");
stream_filter_append(
$outputFile
, 'mcrypt.tripledes'
, STREAM_FILTER_WRITE
, $opts
);
fwrite(
$outputFile
, file_get_contents("inputFileToRead.pdf")
);
fclose($outputFile);
?>
答案 1 :(得分:0)