<?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/%e8%a7%a3%e5%af%86/feed" rel="self" type="application/rss+xml" />
	<link>http://www.linuxbyte.org</link>
	<description>一个Linux Blog</description>
	<lastBuildDate>Thu, 26 Jan 2012 08:13:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>我的GnuPG 使用笔记</title>
		<link>http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html</link>
		<comments>http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html#comments</comments>
		<pubDate>Thu, 04 Jun 2009 20:44:28 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[日常桌面]]></category>
		<category><![CDATA[GnuPG]]></category>
		<category><![CDATA[加密]]></category>
		<category><![CDATA[数字签名]]></category>
		<category><![CDATA[解密]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=431</guid>
		<description><![CDATA[GnuPG全称GNU PrivacyGuard，它是基于公钥/私钥体系的加密工具PGP（Pretty Good Privacy）的开源版本它遵循OpenPGP标准，同时它也是我们平常最常用的非对称工具。 安装GnuPG yum install gnupg or apt-get instll gnup... ]]></description>
			<content:encoded><![CDATA[<p>GnuPG全称GNU PrivacyGuard，它是基于公钥/私钥体系的加密工具PGP（Pretty Good Privacy）的开源版本它遵循OpenPGP标准，同时它也是我们平常最常用的非对称工具。<br />
<strong>安装GnuPG</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> gnupg
or
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> instll gnupg</pre></div></div>

<p>像这样常用的工具基本每个发行版都会带的，所以用你最习惯的方法安装它吧。<br />
<span id="more-431"></span></p>
<p><strong>GnuPG 的使用</strong><br />
1.创建自己的密钥</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">--gen-key</span></pre></div></div>

<p>键入命令后会有类似如下的输出，#后面的是我的注释。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>hew<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ gpg <span style="color: #660033;">--gen-key</span>
gpg <span style="color: #7a0874; font-weight: bold;">&#40;</span>GnuPG<span style="color: #7a0874; font-weight: bold;">&#41;</span> 1.4.5; Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>C<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2006</span> Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is <span style="color: #c20cb9; font-weight: bold;">free</span> software, and you are welcome to redistribute it
under certain conditions. See the <span style="color: #c20cb9; font-weight: bold;">file</span> COPYING <span style="color: #000000; font-weight: bold;">for</span> details.
&nbsp;
Please <span style="color: #000000; font-weight: bold;">select</span> what kind of key you want:
   <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> DSA and Elgamal <span style="color: #7a0874; font-weight: bold;">&#40;</span>default<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> DSA <span style="color: #7a0874; font-weight: bold;">&#40;</span>sign only<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> RSA <span style="color: #7a0874; font-weight: bold;">&#40;</span>sign only<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Your selection? <span style="color: #000000;">1</span> <span style="color: #666666; font-style: italic;">#选择何种算法，一般默认。</span>
DSA keypair will have <span style="color: #000000;">1024</span> bits.
ELG-E keys may be between <span style="color: #000000;">1024</span> and <span style="color: #000000;">4096</span> bits long.
What keysize <span style="color: #000000; font-weight: bold;">do</span> you want? <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2048</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1024</span> <span style="color: #666666; font-style: italic;">#密钥长度，默认2048，我选1024 太长加解密时间也长。</span>
Requested keysize is <span style="color: #000000;">1024</span> bits
Please specify how long the key should be valid.
         <span style="color: #000000;">0</span> = key does not expire
      <span style="color: #000000; font-weight: bold;">&lt;</span>n<span style="color: #000000; font-weight: bold;">&gt;</span>  = key expires <span style="color: #000000; font-weight: bold;">in</span> n days
      <span style="color: #000000; font-weight: bold;">&lt;/</span>n<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>n<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #c20cb9; font-weight: bold;">w</span> = key expires <span style="color: #000000; font-weight: bold;">in</span> n weeks
      <span style="color: #000000; font-weight: bold;">&lt;/</span>n<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>n<span style="color: #000000; font-weight: bold;">&gt;</span>m = key expires <span style="color: #000000; font-weight: bold;">in</span> n months
      <span style="color: #000000; font-weight: bold;">&lt;/</span>n<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>n<span style="color: #000000; font-weight: bold;">&gt;</span>y = key expires <span style="color: #000000; font-weight: bold;">in</span> n years
Key is valid <span style="color: #000000; font-weight: bold;">for</span>? <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">0</span> <span style="color: #666666; font-style: italic;">#密钥有效期，默认长期有效。</span>
Key does not expire at all
Is this correct? <span style="color: #7a0874; font-weight: bold;">&#40;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span> y
&nbsp;
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address <span style="color: #000000; font-weight: bold;">in</span> this form:
    <span style="color: #ff0000;">&quot;Heinrich Heine (Der Dichter) &lt;heinrichh @duesseldorf.de&gt;&quot;</span>
&nbsp;
Real name: lily
Name must be at least <span style="color: #000000;">5</span> characters long
Real name: lily.yu
Email address: linuxbyte<span style="color: #000000; font-weight: bold;">@</span>qq.com
Comment: linuxbyte<span style="color: #000000; font-weight: bold;">@</span>qq.com
You selected this USER-ID:
    <span style="color: #ff0000;">&quot;lily.yu (linuxbyte@qq.com) &lt;linuxbyte @qq.com&gt;&quot;</span>
<span style="color: #666666; font-style: italic;">#输入用户名和邮箱，用户名最好用全名最少5字符。</span>
Change <span style="color: #7a0874; font-weight: bold;">&#40;</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span>ame, <span style="color: #7a0874; font-weight: bold;">&#40;</span>C<span style="color: #7a0874; font-weight: bold;">&#41;</span>omment, <span style="color: #7a0874; font-weight: bold;">&#40;</span>E<span style="color: #7a0874; font-weight: bold;">&#41;</span>mail or <span style="color: #7a0874; font-weight: bold;">&#40;</span>O<span style="color: #7a0874; font-weight: bold;">&#41;</span>kay<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>Q<span style="color: #7a0874; font-weight: bold;">&#41;</span>uit? o
You need a Passphrase to protect your secret key.
<span style="color: #666666; font-style: italic;">#这里会让你输入密码这是你私钥的验证密码</span>
We need to generate a lot of random bytes. It is a good idea to perform
some other action <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">type</span> on the keyboard, move the mouse, utilize the
disks<span style="color: #7a0874; font-weight: bold;">&#41;</span> during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
.+++++++++++++++.+++++++++++++++...++++++++++++++++++++++++++++++.++++++++++.+++++.+++++.+++++.+++++.+++++.++++++++++.+++++++++++++++.+++++.++++++++++.<span style="color: #000000; font-weight: bold;">&gt;</span>+++++........................<span style="color: #000000; font-weight: bold;">&gt;</span>+++++.<span style="color: #000000; font-weight: bold;">&lt;</span> +++++........<span style="color: #000000; font-weight: bold;">&gt;</span>+++++....<span style="color: #000000; font-weight: bold;">&lt;</span> +++++.................+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">type</span> on the keyboard, move the mouse, utilize the
disks<span style="color: #7a0874; font-weight: bold;">&#41;</span> during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++++++++++++.+++++.+++++.+++++++++++++++.+++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.++++++++++<span style="color: #000000; font-weight: bold;">&gt;</span>.+++++<span style="color: #000000; font-weight: bold;">&gt;</span>+++++...................................+++++^^^
gpg: key 2FD93E4F marked <span style="color: #c20cb9; font-weight: bold;">as</span> ultimately trusted
public and secret key created and signed.
&nbsp;
gpg: checking the trustdb
gpg: <span style="color: #000000;">3</span> marginal<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> needed, <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">complete</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> needed, PGP trust model
gpg: depth: <span style="color: #000000;">0</span>  valid:   <span style="color: #000000;">2</span>  signed:   <span style="color: #000000;">0</span>  trust: <span style="color: #000000;">0</span>-, 0q, 0n, 0m, 0f, 2u
pub   1024D<span style="color: #000000; font-weight: bold;">/</span>2FD93E4F <span style="color: #000000;">2009</span>-06-04
      Key fingerprint = BA6F 89DA F2B9 41B5 <span style="color: #000000;">5312</span>  96FB FA32 5AF9 2FD9 3E4F
uid                  lily.yu <span style="color: #7a0874; font-weight: bold;">&#40;</span>linuxbyte<span style="color: #000000; font-weight: bold;">@</span>qq.com<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;/</span>linuxbyte<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>linuxbyte <span style="color: #000000; font-weight: bold;">@</span>qq.com<span style="color: #000000; font-weight: bold;">&gt;</span>
sub   1024g<span style="color: #000000; font-weight: bold;">/</span>D0C255EA <span style="color: #000000;">2009</span>-06-04
<span style="color: #000000; font-weight: bold;">&lt;/</span>linuxbyte<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>heinrichh<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>n<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>这样你的密钥就算生成了，生成的key会保存在～/.gnupg/目录下，其中公钥文件为 pubring.gpg,私钥文件为secring.gpg。</p>
<p><strong>密钥的管理</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-K</span> <span style="color: #666666; font-style: italic;">#列出当前机器上的密钥</span>
&nbsp;
gpg <span style="color: #660033;">-a</span> <span style="color: #660033;">-o</span> lily.key <span style="color: #660033;">--export</span> lily.yu <span style="color: #666666; font-style: italic;">#导出lily 的公钥到lily.key 。</span>
gpg <span style="color: #660033;">-a</span> <span style="color: #660033;">-o</span> lily-secret.key <span style="color: #660033;">--export-secret-keys</span> 2lily.yu <span style="color: #666666; font-style: italic;">#导出lily 的私钥</span>
&nbsp;
gpg <span style="color: #660033;">--delete-keys</span> lily.yu <span style="color: #666666; font-style: italic;">#从公钥钥匙环里删除密钥</span>
gpg <span style="color: #660033;">--delete-secret-keys</span> lily.yu <span style="color: #666666; font-style: italic;">#从私钥钥匙环里删除密钥</span>
gpg <span style="color: #660033;">--delete-secret-and-public-key</span> lily.yu <span style="color: #666666; font-style: italic;">#同时删除公钥私钥</span>
&nbsp;
gpg <span style="color: #660033;">--import</span> filenamepubkey  <span style="color: #666666; font-style: italic;">#导入一个密钥</span></pre></div></div>

<p><strong>用GnuPG 加解密文件</strong></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>
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><strong>用GnuPG 为文件做数字签名</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">-s</span> hello.txt <span style="color: #666666; font-style: italic;">#为hello.txt 加签名，不加 -o 参数会产生一个hello.txt.gpg 文件</span>
gpg <span style="color: #660033;">--verify</span> hello.txt.gpg <span style="color: #666666; font-style: italic;">#验证该文件的签名</span>
&nbsp;
gpg <span style="color: #660033;">-o</span> hello-new.txt <span style="color: #660033;">--clearsign</span> hello.txt <span style="color: #666666; font-style: italic;">#将数字签名直接附加在文件中</span>
gpg <span style="color: #660033;">--verify</span> hello-new.txt <span style="color: #666666; font-style: italic;">#验证</span></pre></div></div>

<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><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/linux-xia-de-wen-jian-jia-mi.html" title="Linux 下的文件加密">Linux 下的文件加密</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></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2009<br />
Source: <a href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html">我的GnuPG 使用笔记</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/gnupg" rel="tag">GnuPG</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%95%b0%e5%ad%97%e7%ad%be%e5%90%8d" rel="tag">数字签名</a>, <a href="http://www.linuxbyte.org/tag/%e8%a7%a3%e5%af%86" rel="tag">解密</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/gnupg" title="GnuPG" rel="tag">GnuPG</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%95%b0%e5%ad%97%e7%ad%be%e5%90%8d" title="数字签名" rel="tag">数字签名</a>, <a href="http://www.linuxbyte.org/tag/%e8%a7%a3%e5%af%86" title="解密" rel="tag">解密</a></p>

<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/wo-de-gnupg-shi-yong-bi-ji.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

