GnuPG 的PGP使用

1. 生成秘钥对(此处采用默认的RSA, 2048位)

$ gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: directory `/home/webadmin/.gnupg' created
gpg: new configuration file `/home/webadmin/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/webadmin/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/webadmin/.gnupg/secring.gpg' created
gpg: keyring `/home/webadmin/.gnupg/pubring.gpg' created
Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 10y

最后生成完成后,会有下列的信息显示:

public and secret key created and signed.

 

2. 查看有哪些公钥

$ gpg --list-keys

 

3. 导出公钥(用于加密)(ASCII格式适合程序中使用)

$ gpg -a -o pubkey.txt --export test01

此处test01是 --list-keys罗列出来的uid。

 

4. 导出私钥(用于解密)

$ gpg -a -o prikey.txt --export-secret-keys test01

 

5. 测试加密和解密

$ gpg  -r test01 -e test.txt

$ gpg -r test01 -o test.txt -d test.txt.gpg

 

posted @ 2014-12-16 16:23  Beef Liu  阅读(619)  评论(0编辑  收藏  举报