GnuPG 的PGP使用

扫码查看

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

$ gpg --gen-key
gpg (GnuPG) 2.0.; Copyright (C) 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:
() RSA and RSA (default)
() DSA and Elgamal
() DSA (sign only)
() RSA (sign only)
Your selection?
RSA keys may be between and bits long.
What keysize do you want? ()
Requested keysize is bits
Please specify how long the key should be valid.
= 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? () 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
05-11 09:39
查看更多