Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 207 章 OpenPGP/OpenGPG(GnuPG)

目錄

207.1. GnuPG
207.1.1. Creating a key (創建key)
207.1.2. --list-keys 列出已存在的證書
207.1.3. Exporting keys (導出key)
207.1.3.1. --export export keys
207.1.3.2. -o, --output use as output file
207.1.4. Importing keys (導入key)
207.1.5. Revoke a key (吊銷key)
207.2. GnuPG For Windows
207.2.1. 生成密鑰對
207.2.2. 列出密鑰
207.2.3. 驗證簽字
207.3. EMail-Security
207.4. Smart Card
207.5. 例子
207.5.1. 加密檔案

下載PGP: http://www.pgp.com/

下載OpenPGP: http://www.pgpi.org/

207.1. GnuPG

GnuPG

~/.gnupg/gpg.conf 	 – 配置檔案
~/.gnupg/trustdb.gpg – 信任庫
~/.gnupg/pubring.gpg – 公鑰庫
~/.gnupg/secring.gpg – 私鑰庫
		

207.1.1. Creating a key (創建key)

--gen-key generate a new key pair

			
neo@neo-laptop:~$ gpg --gen-key
gpg (GnuPG) 1.4.11; Copyright (C) 2010 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.

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?
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) 1y
Key expires at Tuesday, October 22, 2013 PM03:25:35 HKT
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: Neo Chan
Email address: 324@example.com
Comment: Office Email
You selected this USER-ID:
    "Neo Chan (Office Email) <324@example.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. 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.

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 282 more bytes)
.......+++++
.......+++++
We need to generate a lot of random bytes. 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.
..+++++
..+++++
gpg: key CEF09301 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2013-10-22
pub   2048R/CEF09301 2012-10-22 [expires: 2013-10-22]
      Key fingerprint = C5B7 50EF 762F 3F7F 1AE5  8AEC AF10 D50D CEF0 9301
uid                  Neo Chan (Office Email) <324@example.com>
sub   2048R/0BF4D523 2012-10-22 [expires: 2013-10-22]
			
			

207.1.2. --list-keys 列出已存在的證書

			
$ gpg --list-keys
/home/neo/.gnupg/pubring.gpg
----------------------------
pub   1024R/63268A35 2013-09-11
uid                  Neo Chen (netkiller) <netkiller@msn.com>
sub   1024R/F4F946F9 2013-09-11
				
			

207.1.3. Exporting keys (導出key)

207.1.3.1. --export export keys

				
gpg --export -a
				
				

207.1.3.2. -o, --output use as output file

				
$ gpg --export -a -o test.asc
$ gpg --output yourname.asc --export -a
				
				

207.1.4. Importing keys (導入key)

--import import/merge keys

			
neo@neo-laptop:~$ gpg --import 409.asc
gpg: key 4D3A0803: public key "Phoenix.L <409@example.com>" imported
gpg: key CEF09301: "Neo Chan (Office Email) <324@example.com>" not changed
gpg: Total number processed: 2
gpg:               imported: 1  (RSA: 1)
gpg:              unchanged: 1

			
			

207.1.5. Revoke a key (吊銷key)

			
gpg --gen-revoke