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.
In this tutorial, I will describe how to create an encrypted zip file on Linux.
Method One
The zip command line tool provides an encryption option. The encryption algorithm used by zip command is. 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.
To create an encrypted zip file with zip:
To uncompress a zip file that is encrypted with zip command:
Archive: secure.zip [secure.zip] doc.pdf password:
Method Two
7z file archiver can produce zip-format archives with more secure encryption scheme. According to , 7z archiver supports AES-256 encryption algorithm with SHA-256 hash algorithm based key generation.
To create an encrypted zip file with 7z archiver:
To uncompress a zip file that is encrypted with 7za command:
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) :
Method Three
Another way to create a secure zip archive is to use GnuPG's symmetric key encryption.
To create an encrypted compressed tar archive with GnuPG:
To uncompress an archive file encrypted with GnuPG:
文章来源:http://blog.ashurex.com/2012/07/17/encrypting-tar-gz-gzip-file-openssl/
Encrypt a tar file with OpenSSL, much easier than gpg.
Encrypting:
tar cvzf - mysql_dump.sql | openssl des3 -salt -k #YOUR PASSWORD# | dd of=encrypted_mysql_dump
Decrypting:
dd if=encrypted_mysql_dump |openssl des3 -d -k #YOUR PASSWORD# |tar xvzf -