<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LinuxByte &#187; 文件加密</title>
	<atom:link href="http://www.linuxbyte.org/tag/%e6%96%87%e4%bb%b6%e5%8a%a0%e5%af%86/feed" rel="self" type="application/rss+xml" />
	<link>http://www.linuxbyte.org</link>
	<description>一个Linux Blog</description>
	<lastBuildDate>Tue, 22 Jun 2010 15:10:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux 下的文件加密</title>
		<link>http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html</link>
		<comments>http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html#comments</comments>
		<pubDate>Fri, 26 Jun 2009 05:59:01 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[系统管理]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[加密]]></category>
		<category><![CDATA[文件加密]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=444</guid>
		<description><![CDATA[以前我在blog 写过两篇关于linux 下目录加密的文章用Cryptkeeper和EncFS 完成目录加密和用Cryptsetup LUKS 加密目录，今天我想说说文件加密，先说简单的用VIM 加密文本文件：
vim 加密使用 -x 参数，即

... ]]></description>
			<content:encoded><![CDATA[<p>以前我在blog 写过两篇关于linux 下目录加密的文章<a title="Permanent Link to 用Cryptkeeper和EncFS 完成目录加密" rel="bookmark" href="http://www.linuxbyte.org/yong-cryptkeeperhe-encfs-wan-cheng-mu-lu-jia-mi.html">用Cryptkeeper和EncFS 完成目录加密</a>和<a title="Permanent Link to 用Cryptsetup LUKS 加密目录" rel="bookmark" href="http://www.linuxbyte.org/cryptsetup-luks-jiami.html">用Cryptsetup LUKS 加密目录</a>，今天我想说说文件加密，先说简单的<strong>用VIM 加密文本文件</strong>：</p>
<p>vim 加密使用 -x 参数，即</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #660033;">-x</span> myfile</pre></div></div>

<p>然后会提示让你输入两次密码，这样就算给你的文件加上密码了，下次要看文件用VIM 打开会要求输入密码，输入错误密码则会得到一堆乱码，用其他编辑器打开也是一堆乱码。要清除密码只要在正确打开文件后用 &#8220;:X&#8221; 指令，然后给一个空密码就行。<br />
当然vim 加密还是有很多局限的，算法弱并且中间会有交换文件，交换文件是不加密的，虽然有&#8221;-n&#8221; 参数可以不使用交换文件但不用交换文件让我不得不时刻记得要存盘。</p>
<p>vim加密的算法很弱所以要更好的保护你的文件你需要专业的加密工具，如openssl，gpg。<span id="more-444"></span><br />
<strong>对称加密：</strong></p>
<p>a.用openssl 加密文件:</p>
<p>加密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl enc <span style="color: #660033;">-aes-<span style="color: #000000;">128</span>-ecb</span> <span style="color: #660033;">-e</span> <span style="color: #660033;">-in</span> myfile-out myfile-aes</pre></div></div>

<p>解密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl enc <span style="color: #660033;">-aes-<span style="color: #000000;">128</span>-ecb</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-in</span> myfile-aes <span style="color: #660033;">-out</span> myfile</pre></div></div>

<p>enc  后面跟你具体的加密算法<br />
-aes-128-ecb 所使用的算法<br />
-e/-d 加密/解密<br />
-in 要被加/解密的文件<br />
-out 被加/解密后的文件</p>
<p>b.用GnuPG加密文件</p>
<p>关于GnuPG 之前有另一篇博文 <a title="Permanent Link to 我的GnuPG 使用笔记" rel="bookmark" href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html">我的GnuPG 使用笔记</a>有关于GnuPG 更多的内容这里只说一下加密。<br />
加密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-c</span> myfile <span style="color: #666666; font-style: italic;">#输入密码后会产生一个myfile.gpg 文件，这就是加密后的文件。</span></pre></div></div>

<p>解密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-o</span> myfile <span style="color: #660033;">-d</span> myfile.gpg <span style="color: #666666; font-style: italic;">#解密文件myfile.gpg 并将解密后的文件输出为myfile。</span></pre></div></div>

<p><strong>非对称加密</strong><br />
前面说的都是对称加密，现在说一下非对称加密，这个应该说是我们目前使用的最安全的方法了。<br />
加密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-ea</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;lily.yu&quot;</span> hello.txt 
<span style="color: #666666; font-style: italic;">#使用lily.yu 这个密钥加密hello.txt，你会得到一个加密后的文件hello.txt.asc。-a 表示已ASCII 输出.</span></pre></div></div>

<p>解密</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-o</span> new.txt <span style="color: #660033;">-d</span> hello.txt.asc <span style="color: #666666; font-style: italic;">#解密hello.txt.asc 文件并输出到 new.txt 文件。</span></pre></div></div>

<p>至于如何创建密钥管理密钥请参看<a title="Permanent Link to 我的GnuPG 使用笔记" rel="bookmark" href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html">我的GnuPG 使用笔记</a></p>
<h3  class="related_post_title">与本文关系暧昧的文字</h3><ul class="related_post"><li><a href="http://www.linuxbyte.org/yi-zu-linux-zhu-ti-bi-zhi.html" title="一组 Linux 主题壁纸">一组 Linux 主题壁纸</a></li><li><a href="http://www.linuxbyte.org/firegpg-fei-chang-hao-yong-de-gpg-gong-ju.html" title="FireGPG-非常好用的GPG工具">FireGPG-非常好用的GPG工具</a></li><li><a href="http://www.linuxbyte.org/linuxzhi-fu-peng-chang-windows-7shu-qi-da-mu-zhi.html" title="Linux之父捧场Windows 7竖起大拇指">Linux之父捧场Windows 7竖起大拇指</a></li><li><a href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html" title="我的GnuPG 使用笔记">我的GnuPG 使用笔记</a></li><li><a href="http://www.linuxbyte.org/yong-cryptkeeperhe-encfs-wan-cheng-mu-lu-jia-mi.html" title="用Cryptkeeper和EncFS 完成目录加密">用Cryptkeeper和EncFS 完成目录加密</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/cryptsetup-luks-jiami.html" title="用Cryptsetup LUKS 加密目录">用Cryptsetup LUKS 加密目录</a></li><li><a href="http://www.linuxbyte.org/engarde-secure-linux-3021-released.html" title="EnGarde Secure Linux 3.0.21 发布">EnGarde Secure Linux 3.0.21 发布</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2009<br />
Source: <a href="http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html">Linux 下的文件加密</a><br />
<a href="http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html#comments">2 comments</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/linux" rel="tag">linux</a>, <a href="http://www.linuxbyte.org/tag/%e5%8a%a0%e5%af%86" rel="tag">加密</a>, <a href="http://www.linuxbyte.org/tag/%e6%96%87%e4%bb%b6%e5%8a%a0%e5%af%86" rel="tag">文件加密</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://www.linuxbyte.org/tag/%e5%8a%a0%e5%af%86" title="加密" rel="tag">加密</a>, <a href="http://www.linuxbyte.org/tag/%e6%96%87%e4%bb%b6%e5%8a%a0%e5%af%86" title="文件加密" rel="tag">文件加密</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/help-fun-input-toy.html" title="致Linux开发者社区：新输入法Fitx开发需要大家帮忙 (2008-02-16)">致Linux开发者社区：新输入法Fitx开发需要大家帮忙</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell (2009-04-09)">用shc 加密shell</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/cryptsetup-luks-jiami.html" title="用Cryptsetup LUKS 加密目录 (2009-03-06)">用Cryptsetup LUKS 加密目录</a> (1)</li>
	<li><a href="http://www.linuxbyte.org/yong-cryptkeeperhe-encfs-wan-cheng-mu-lu-jia-mi.html" title="用Cryptkeeper和EncFS 完成目录加密 (2009-04-27)">用Cryptkeeper和EncFS 完成目录加密</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html" title="我的GnuPG 使用笔记 (2009-06-05)">我的GnuPG 使用笔记</a> (1)</li>
</ul>


<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
