簡體   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