GnuPG简单使用

 假设Alice要给Bob发送一封邮件(email),内容如下:
Hello! I am Alice
1. Alice和Bob各自用以下命令生成自己的公钥/私钥对:
gpg --gen-key
前三个选择可以选默认的,然后输入姓名,Email以及评论(评论可以省略)。确认后需要键入一个密码来保护自己的私钥(以后每次使用私钥时都必须键入这个密码)。接下来GnuPG会生成一对公钥/私钥,此过程需要一定时间,可以通过移动鼠标或者键盘输入来加速此过程( It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.)
2. 通过以下命令查看生成的钥匙对:
gpg --list-keys
比如Alice查看到的内容是:
pub   1024D/D9B7B098 2009-11-22
uid                  Alice <alice@abc.com>
sub   2048g/186382BF 2009-11-22
3. Alice需要Bob的公钥来对邮件加密,所以Bob需要先导出自己的公钥,命令如下:
gpg --armor --output bob.asc --export bob@bob.com
Bob的公钥被导出到bob.asc文件中。Bob可以将此文件发送给Alice。
4. Alice获得bob.asc后,要先将Bob的这个公钥导入自己的钥匙串,命令如下:
 gpg --import bob.asc
5. 接着Alice要确认此公钥的确是Bob的,方法是查看此公钥的fingerprint,并联系Bob对比这个fingerprint。(Bob可以通过gpg --fingerprint bob@bob.com来查看自己的fingerprint)。如果核对成功,那么Alice可以用自己的私钥对这个公钥签名,表示“我确认这个公钥确实是Bob的”。确认公钥和对公钥签名有以下两种方式:
--------------------------------
gpg --edit-key bob@bob.com
Command>fpr //查看fingerprint
Command>sign //没错,那么签名
Command>check //检查签名
Command>quit //退出
---------------------------------
gpg --fingerprint bob@bob.com //查看fingerprint
gpg --sign-key bob@bob.com //没错,那么签名
gpg --check-sigs bob@bob.com //检查签名
---------------------------------
6. Alice对email签名,然后用Bob的公钥加密。签名和加密可以用一条命令完成:
gpg -o email.asc -ea -s -r bob@bob.com email
然后Alice将email.asc发给Bob
7. Bob收到email.asc后,用以下命令:
gpg -d email.asc
然后正确键入自己的密码,就可以用自己的私钥对email解密,看到其真正内容了!
如果Bob也要验证这个信息真的是Alice发过来的,那么他只需要知道Alice的公钥,并将其导入即可。

 

参考资料:
http://www.lupaworld.com/441/viewspace-224.html
http://www.gentoo.org/doc/zh_tw/gnupg-user.xml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值