繁体   English   中英

发送加密文件(zip或txt)-通过PHP-在Windows PC上可打开

[英]Send encrypted file (zip or txt) - via PHP - openable on Windows PC

我需要通过电子邮件向用户发送一些最少的数据(但必须将其加密)。

他们将需要对附件进行DL处理并使用某种易于使用的软件(PC / MAC)对其进行解密...这里有什么想法吗?

我的第一个想法是制作一个加密的zip文件,使其可以使用7zip或winzip打开...但是我发现使用典型的PHP / Linux应用程序无法实现。

您可以使用mcryptBlowfish来加密邮件。 您可以找到许多针对河豚的加密/解密程序,例如... http://www.di-mgt.com.au/mysecret.html

<?php

    $key = 'too many secrets?';
    $text = 'If you are paranoid, we know who you are and what you want. Stay online so we can trace you.';

    $crypt_text = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_ECB);

    var_dump($crypt_text);

    $plain_text = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $crypt_text, MCRYPT_MODE_ECB);

    var_dump($plain_text);

?>

测试:

string(96) "dà¨gþJ\V$3Äö,'  [y€&”¼‚\•òÏ=$ÅdG|ÀœÀbáÌɽûÝÉ·'þØ?I½}8óTé5<-‹ôÞ¶Ÿ°ÅMcCê®JxØ@RIú£Ç‹™xÞ"
string(96) "If you are paranoid, we know who you are and what you want. Stay online so we can trace you.����"

我链接的程序需要这样的输入文件(您可以在电子邮件中轻松地将其制成)。

----- BEGIN MYSECRET ----- TVn8APjdMOdLPUBQ2OWsEh7wWnihhKKOKf11Vj0oo4pM20BPwrRXJyL + nBOL dpxdc + PQQoQlr0Vz1n1Fv932HQ16DG712ui69T3O0jI3NfX8jRjtZkal / SFY Vu9JJEWPfZ2Ri1fkfOCqe9ZvFEmJ78BcUVmf37SYbgKi8UcAv4i1heHfJ05e nde6nFeiyDptYflT7SiIGHcO1cVya22b1OLHakAE2paS1OJqQrHYc + 5wEAdo DU / 0BmNvNNYOekmHZT19C1 + cIwZFo3ACLRN44gZffx + KIng570UcoNYa7NWn hzt6gvQHXEp2jnE = ----- END MYSECRET -----

这不是将归档文件存储在服务器上并通过电子邮件发送到php页面的链接的解决方案,该页面可以获取特定的zip,并在用户使用基本身份验证登录后将其发送给用户。 因此,只有知道密码的用户才能执行该脚本并下载文件。 你怎么看?

典型的PHP应用程序怎么办? 您当然可以压缩文件: http : //php.net/manual/en/book.zip.php

我使用GNUPG: http ://www.gnupg.org/

您需要访问Web服务器才能安装它,或者如果已安装,则需要添加密钥环。

然后,您可以将其与exec调用一起使用,也可以与GNUPG PECL扩展一起使用。

这样做的问题在于,用户必须使用用于加密它的相同电子邮件地址($ gpgrecipient)创建一个密钥,并且在加密之前,他们必须这样做,然后将其上传到公共密钥服务器(该软件将执行的操作)。 但是,该软件非常简单,并且是跨平台的。

对于我的php加密脚本,我使用:

<?php
//error_reporting(E_ALL);
echo 'GNUPG Test<br /><br />';

putenv("GNUPGHOME=/home/me/.gnupg");

$gpg = '/usr/bin/gpg';
$gpgrecipient = 'ben@mydomain.com';
$plaintext = 'This should be encrypted!!!!';



$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin 
   1 => array("pipe", "w"),  // stdout 
   2 => array("file", "/usr/home/me/error-output.txt", "a") // stderr is a file to write to
);

$cwd = '/usr/bin/';
$env = array('GNUPGHOME' => '/usr/home/me/.gnupg');


$process = proc_open("gpg --no-auto-check-trustdb -q --auto-key-locate keyserver --no-secmem-warning --lock-never -e -a -r {$gpgrecipient}", 
                        $descriptorspec, $pipes, $cwd, $env);

if (is_resource($process)) {
    // $pipes now looks like this:
    // 0 => writeable handle connected to child stdin
    // 1 => readable handle connected to child stdout

    fwrite($pipes[0], $plaintext);
    fclose($pipes[0]);

    $encrypted = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    // It is important that you close any pipes before calling
    // proc_close in order to avoid a deadlock
    $return_value = proc_close($process);

 //   echo "\n\n command returned $return_value\n";

    $message = "

This is what we should have ideally (Encrypted Emails). 
Unencrypted text - name, date of arrival, etc. 
This part only Is encrypted and requires a password to view:

{$encrypted} 

More Unencrypted text at the end";


mail($mailrecp, 'Encrypted Emails Example', $message);

}


?>

这只会加密电子邮件的一部分,我使用雷鸟和enigmail进行检索。

您可以更改它以输入文件,并将其附加到电子邮件中。

您甚至可能会找到一个准系统gnupg应用程序,该应用程序创建密钥并将其上传到公共服务器,解密文件等。等等。

如果数据真的很敏感,我认为GnuPG是一个不错的选择。

说处理只需要发送至您控制的电子邮件的在线预订要比您需要的要好得多,但是我想我会把它扔在那里。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM