发送加密文件(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应用程序。

可以使用mcrypt和Blowfish对消息进行加密。你可以为Blowfish找到许多加密/解密程序,例如…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+nBOLdpxdc + PQQoQlr0Vz1n1Fv932HQ16DG712ui69T3O0jI3NfX8jRjtZkal/sFyVu9JJEWPfZ2Ri1fkfOCqe9ZvFEmJ78BcUVmf37SYbgKi8UcAv4i1heHfJ05ende6nFeiyDptYflT7SiIGHcO1cVya22b1OLHakAE2paS1OJqQrHYc + 5 weadoDU/0 bmnvnnyoekmhzt19c1 + cIwZFo3ACLRN44gZffx + KIng570UcoNYa7NWnhzt6gvQHXEp2jnE =——结束MYSECRET

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

典型的PHP应用程序不可能发生什么?当然可以压缩文件:http://php.net/manual/en/book.zip.php

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

你需要访问你的web服务器来安装它,或者如果它已经安装了,添加你的keyring。

然后你可以使用exec调用,或者GNUPG PECL扩展。

这样做的问题是,用户必须使用您用来加密它的相同电子邮件地址($ gpreceiver)创建密钥,并且他们必须在您加密它之前这样做,并将其上传到公钥服务器(软件会这样做)。然而,软件是非常容易的,它是跨平台的。

对于我的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);
}

?>

这只加密电子邮件的一部分,我用thunderbird和enigmail检索。

你可以把它改成输入一个文件,并把它附加到电子邮件中。

你甚至可以找到一个裸gnupg应用程序,它创建一个密钥并将其上传到公共服务器,解密文件,等等。等

如果数据非常敏感,我认为GnuPG是一个很好的选择。

这是说处理在线预订,只需要去一个电子邮件,你控制,比你需要什么,但我想我会把这个扔在那里。