使用 PHP 创建加密的 zip 存档

Create an encrypted zip archive with PHP(使用 PHP 创建加密的 zip 存档)
本文介绍了使用 PHP 创建加密的 zip 存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在寻找一种将 .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 存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)