問題描述
我正在尋找一種將 .txt 文件加密為 zip 文件的方法,但采用安全的密碼保護方式.我的目標是將此文件通過電子郵件發送給我,而任何人都無法閱讀附件的內容.
I am searching for a way to encrypt a .txt file into a zip, but in a secure password protected way. My goal is to email this file to me, without anyone being able to read the content of the attachment.
有誰知道一種簡單且最重要的是安全的方法來實現這一目標?我可以創建 zip 檔案,但我不知道如何加密它們,也不知道這有多安全.
Does anybody know an easy, and above all, secure way to accomplish this ? I can create zip archives, but I do not know how to encrypt them, or, how secure this is.
推薦答案
注意:這個答案推薦了一種已知的加密方法不安全,即使密碼很好.請查看評論中的鏈接和 AES 上的 Winzip QA.支持 in-php AES zip 加密附帶 php 7.2(和 libzip 1.2.0),這意味著答案也很快就會過時.在那之前查看此答案了解如何調用 7z 而不是 zip 命令,它支持 winzip 的AES 加密.
Note: this answer recommends a cryptographic method that is known insecure, even with good password. Please see link from comments and the Winzip QA on AES. Support for in-php AES zip encryption arrives with php 7.2 (and libzip 1.2.0), which means this answer will soon be outdated too. Until then see this answer for how to call out to 7z instead of the zip command, which supports winzip's AES encryption.
你可以使用這個:
<?php echo system('zip -P pass file.zip file.txt'); ?>
其中 pass 是密碼,file.txt 將被壓縮到 file.zip 中.這應該適用于 Windows 和 Linux,您只需要獲得適用于 Windows 的免費 zip 版本( http://www.info-zip.org/Zip.html#Win32 )
Where pass is the password, and file.txt will be zipped into file.zip. This should work on Windows and Linux, you just need to get a free version of zip for Windows ( http://www.info-zip.org/Zip.html#Win32 )
這種安全性可以被蠻力攻擊、字典攻擊等破壞.但這并不容易,特別是如果你選擇了一個又長又難猜的密碼.
This kind of security can be broken by brute force attacks, dictionary attacks and etc. But it's not that easy, specially if you chose a long and hard to guess password.
這篇關于使用 PHP 創建加密的 zip 存檔的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!