首页 > 代码库 > GnuPG 的PGP使用

GnuPG 的PGP使用

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

$ gpg --gen-keygpg (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 createdgpg: new configuration file `/home/webadmin/.gnupg/gpg.conf createdgpg: WARNING: options in `/home/webadmin/.gnupg/gpg.conf are not yet active during this rungpg: keyring `/home/webadmin/.gnupg/secring.gpg createdgpg: keyring `/home/webadmin/.gnupg/pubring.gpg createdPlease 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? 1RSA keys may be between 1024 and 4096 bits long.What keysize do you want? (2048) Requested keysize is 2048 bitsPlease 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 yearsKey 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  -r test01 -e test.txt$ gpg -r test01 -o test.txt -d test.txt.gpg

 

GnuPG 的PGP使用