码迷,mamicode.com
首页 > 其他好文 > 详细

加密和解密 tar

时间:2017-03-16 22:26:12      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:tar   密码   

    平时我们使用惯了tar来对文件和文件夹来进行压缩和解压,但是有时候需要像windows上rar压缩软件一样,在压缩的时候指定密码,然后在解压的时候指定压缩时候密码就可以解压。

a. 没有密码正常操作。

  1. 压缩

realcloud@127:~$ tar zcvf a.tar.gz 1.txt 
1.txt
realcloud@127:~$ ls a.tar.gz 
a.tar.gz

2. 解压

realcloud@127:~$ rm -rf 1.txt
realcloud@127:~$ tar zxvf a.tar.gz 
1.txt
realcloud@127:~$ ls 1.txt 
1.txt


b. 有密码操作

1. 带密码压缩,

realcloud@127:~$ ls
1.txt
realcloud@127:~$ cat 1.txt 
1
realcloud@127:~$ tar -zcvf - 1.txt| openssl des3 -salt -k password -out 1.tar.gz
1.txt
realcloud@127:~$ ls
1.tar.gz  1.txt

其中password就是密码,替换成你想输入的密码。


2. 带密码解压

realcloud@127:~$ rm -rf 1.txt
realcloud@127:~$ openssl des3 -d -k password -salt -in 1.tar.gz | tar xzf -
realcloud@127:~$ ls
1.tar.gz  1.txt
realcloud@127:~$ cat 1.txt
1

其中password就是你压缩时候的加的密码。最后的 - 表示释放所有文件

本文出自 “Promise(许诺)” 博客,请务必保留此出处http://caimengzhi.blog.51cto.com/9787265/1907388

加密和解密 tar

标签:tar   密码   

原文地址:http://caimengzhi.blog.51cto.com/9787265/1907388

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!