Linux下创建加密的压缩文件

Chinese:假设你想创建一个zip归档文件,并且具有密码保护,这样不管是谁试图解压这个zip文件时候,都必须知道正确的密码。在Linux上,有几种方法可以加密ZIP文件,或者对zip文件进行密码保护。

English:Suppose you want to create a zip archive, but with password protection, so that whoever tries to uncompress the zip file must know the right password. On Linux, there are several ways to encrypt and password protect a zip file.
下面我们来介绍常用的3种加密方式:

方法一(Method one):

zip命令行工具提供了一个加密选项。 zip命令所使用的是PKZIP加密算法。 PKZIP算法被称为是不安全的。此外,设置的密码,被以纯文本显示,使得它更加脆弱。(The zip command line tool provides an encryption option. The encryption algorithm used by zip command is PKZIP stream cipher. The PKZIP algorithm is known to be insecure. Also, the fact that the password is typed and shown in plain text makes it even more vulnerable.)
1.使用ZIP命令创建一个加密的ZIP文件(To create an encrypted zip file with zip:):

$ zip --password MY_SECRET j4mlcom.zip doc.pdf doc2.pdf doc3.pdf

2.解压缩加密文件时,会提示要求输入密码(To uncompress a zip file that is encrypted with zip command:):

$ unzip secure.zip

Archive: secure.zip
[secure.zip] doc.pdf password:

方法二(Method Two)
使用7z进行文件归档,可以创建更加安全的加密zip文件,7z使用AES-256加密算法,SHA-256散列算法生成密钥。(7z file archiver can produce zip-format archives with more secure encryption scheme. According to the official description, 7z archiver supports AES-256 encryption algorithm with SHA-256 hash algorithm based key generation.)
1.使用7z创建一个zip文件(To create an encrypted zip file with 7z archiver:):

$ 7za a -tzip -pMY_SECRET -mem=AES256 secure.zip doc.pdf doc2.pdf doc3.pdf

2.解压缩加密文件(To uncompress a zip file that is encrypted with 7za command:):

$ 7za e secure.zip

7-Zip (A) [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)

Processing archive: secure.zip

Extracting doc.pdf
Enter password (will not be echoed) :

扫描二维码关注公众号,回复: 1188558 查看本文章

方法三(Method Three)
Another way to create a secure zip archive is to use GnuPG’s symmetric key encryption.

1.To create an encrypted compressed tar archive with GnuPG:

$ tar czvpf – doc.pdf doc2.pdf doc3.pdf | gpg --symmetric --cipher-algo aes256 -o secure.tar.gz.gpg

2.To uncompress an archive file encrypted with GnuPG:

$ gpg -d secure.tar.gz.gpg | tar xzvf -

转载请注明来源:J4ML
本文地址:http://www.j4ml.com/archives/4391

猜你喜欢

转载自shinepaopao.iteye.com/blog/1943509