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

发布于 2024-12-11 00:13:41 字数 192 浏览 0 评论 0原文

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

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

我的第一个想法是制作一个加密的 zip 文件,可以使用 7zip 或 winzip 打开......但我发现这对于典型的 PHP/Linux 应用程序来说是不可能发生的。

I have a need to send some minimal data via email to users (but it must be encrypted).

They would need to DL the attachment and decrypt it with some kind of easy to use software (PC / MAC)... any ideas here?

My first thought is to make an encrypted zip file that they can open with 7zip or winzip... but I have found that it can't happen with a typical PHP/Linux app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

漆黑的白昼 2024-12-18 00:13:41

您可以使用 mcryptBlowfish 加密消息。您可以找到许多 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.����"

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

-----开始我的秘密----- TVn8APjdMODLPUBQ2OWsEh7wWnihhKKOKf11Vj0oo4pM20BPwrRXJyL+nBOL
dpxdc+PQQoQlr0Vz1n1Fv932HQ16DG712ui69T3O0jI3NfX8jRjtZkal/sFy
Vu9JJEWPfZ2Ri1fkfOCqe9ZvFEmJ78BcUVmf37SYbgKi8UcAv4i1heHfJ05e
nde6nFeiyDptYflT7SiIGHco1cVya22b1OLHakaAE2paS1OJqQrHYc+5weado
DU/0BmNvNNYOekmHZT19C1+cIwZFo3ACLRN44gZffx+KIng570UcoNYa7NWn
hzt6gvQHXEp2jnE=
-----结束我的秘密-----

You can use mcrypt and Blowfish to encrypt message. You can find many encrypt/decrypt programs for Blowfish eg... 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);

?>

Test:

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.����"

The program I've linked needs input file like this (you can easily make it like that in email).

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

┊风居住的梦幻卍 2024-12-18 00:13:41

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

Isn't a solution for you to store the archives on the server, and send by email link to php page that can fetch specific zip and send it to the user after the user login with basic authentication. So only the users that know the password can execute that script and download the file.
What do you think?

挽清梦 2024-12-18 00:13:41

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

What can't happen with a typical PHP app? You can certainly zip files: http://php.net/manual/en/book.zip.php

爱的那么颓废 2024-12-18 00:13:41

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

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

然后您可以将其与 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 = '[email protected]';
$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 是一个不错的选择。

对于处理在线预订来说,只需要转到您控制的一封电子邮件,这比您需要的要好得多,但我想我会把它扔在那里。

I use GNUPG: http://www.gnupg.org/

You will need access to your webserver to either install it, or if it is installed, to add your keyring.

Then you can either use it with an exec call, or the GNUPG PECL extension.

The problem with this, is that the user has to create a key using the same email address ($gpgrecipient) that you use to encrypt it, and they have to do it BEFORE you encrypt it, and upload it to a public key server(which the software will do). However the software is pretty easy, and it is cross platform.

For my php encryption script, I use:

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

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

$gpg = '/usr/bin/gpg';
$gpgrecipient = '[email protected]';
$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);

}


?>

This only encrypts a section of an email, which I retrieve with thunderbird and enigmail.

You could change it to input a file, and attach it to an email.

You could even probably find a barebones gnupg app that creates a key and uploads it to a public server, decrypts a file, etc.. etc..

If the data is really sensitive, I think GnuPG is a good option.

It is a lot better for say handling online reservations that only need to go to one email that you control, than for what you are needing, but I thought I would throw this out there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文