最近打算发布一个maven项目到中央仓库,根据教程发现需要使用到gpg4win这个软件生成密钥对,于是从https://www.gpg4win.org/下载并安装完软件,根据提示运行过程如下:C:\Users\Administrator>gpg --version
gpg (GnuPG) 2.0.30 (Gpg4win 2.3.1)
libgcrypt 1.6.5
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Home: C:/Users/Administrator/AppData/Roaming/gnupg
Supported algorithms:
Pubkey: RSA, RSA, RSA, ELG, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
C:\Users\Administrator>gpg --gen-key
gpg (GnuPG) 2.0.30; Copyright (C) 2015 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? 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
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: shuiguang
Email address: xxx@xxx.com
Comment: maven
You selected this USER-ID:
"shuiguang (maven) "
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.
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 9B082DA8 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
pub 2048R/9B082DA8 2016-06-23
Key fingerprint = 2132 F055 4E65 0D48 856F 4023 EC18 8AA9 9B08 2DA8
uid [ultimate] shuiguang (maven)
sub 2048R/0F50CD3B 2016-06-23
中间会弹出一个输入Passphase的对话框提示输入一个密码,该密码请牢记不要告诉任何人。
查看公钥:gpg --list-keys
C:\Users\Administrator>gpg --list-keys
C:/Users/Administrator/AppData/Roaming/gnupg/pubring.gpg
--------------------------------------------------------
pub 2048R/9B082DA8 2016-06-23
uid [ultimate] shuiguang (maven)
sub 2048R/0F50CD3B 2016-06-23
可见这里的公钥的 ID 是:9B082DA8,很明显是一个 16 进制的数字,以后会用到。
将公钥发布到 PGP 密钥服务器gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 9B082DA8
此后,可使用本地的私钥来对上传构件进行数字签名,而下载该构件的用户可通过上传的公钥来验证签名,也就是说,大家可以验证这个构件是否由本人上传的,因为有可能该构件被坏人给篡改了。
查询公钥是否发布成功gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 9B082DA8
实际上就是从 key server 上通过公钥 ID 来接收公钥,此外,也可以到 sks-keyservers.net 上通过公钥 ID 去查询。
如果需要删除某一对密钥对,例如可以执行先删除私钥:gpg --delete-secret-keys 9B082DA8
执行过程中会提示输入y/N,然后删除公钥:gpg --delete-keys 9B082DA8
输入y完成删除,再次查询就没有这一对密钥了。gpg --list-keys
参考:
对于一个已经生成的GPG密钥对,想对其中的用户名称,注释信息进行修改,那么怎么办呢?
重新生成密钥?
修改已经生成的密钥?
重新生成密钥很简单了,但是这会造成多个密钥的选择问题,那么在这里就对已经生成的密钥进行修改的方法作一个介绍。
下面就听慢慢道来:
1、首先,在命令行输入如下命令进入修改密钥信息的界面:
gpg --edit-key test@test.com
gpg (GnuPG) 1.4.16; Copyright (C) 2013 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.
私钥可用。
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
绝对 (1). yy_test1 (yy_email_gpg)
gpg>
2、使用list可以看到当前用户的 密钥及用户标识(即用户名,注释):
gpg> list
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
绝对 (1)* yy_test1 (yy_email_gpg)
3、添加一个用户标识:
gpg> adduid
真实姓名: [yy]yy Ming Xiao
电子邮件地址: test@test.com
注释: DSC security
您选定了这个用户标识:
“[yy]yy Ming Xiao (DSC security) ”
更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)? O
您需要输入密码,才能解开这个用户的私钥:“yy_test1 (yy_email_gpg) ”
4096 位的 RSA 密钥,钥匙号 DPPPPPPP,建立于 2015-03-16
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
绝对 (1)* yy_test1 (yy_email_gpg)
未知 (2). [yy]yy Ming Xiao (DSC security)
4、删除/注销原来的UID信息:
要先使用uid 1选中将要删除的标识号,这里我们要删除的标识号为1;
gpg> uid 1
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
绝对 (1)* yy_test1 (yy_email_gpg)
未知 (2). [yy]yy Ming Xiao (DSC security)
这儿又可以分为两种情况,
1)、对于还没有上传到密钥服务器的密钥进行删除密钥即可。
2)、对于已经上传到密钥服务器的密钥来说,若不想原来的密钥再进行使用,那么就使用注销命令进行标识的注销。
1)、对于还没有上传到密钥服务器的密钥进行删除密钥即可。
绝对(1)*标有*的即表示当前被选中的标识,再使用deluid命令删除掉1号标识即可:
gpg> deluid
真的要删除这个用户标识吗?(y/N) y
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
未知 (1). [yy]yy Ming Xiao (DSC security)
2)、对于已经上传到密钥服务器的密钥来说,若不想原来的密钥再进行使用,那么就使用注销命令进行标识的注销。
gpg> revuid
真的要吊销这个用户标识吗?(y/N) y
请选择吊销的原因:
0 = 未指定原因
4 = 用户标识不再有效
Q = 取消
(也许您会想要在这里选择 4)
您的决定是什么? 4
请输入描述(可选);以空白行结束:
>
吊销原因:用户标识不再有效
(不给定描述)
这样可以吗? (y/N) y
您需要输入密码,才能解开这个用户的私钥:“yy_test1 (yy_email_gpg) ”
4096 位的 RSA 密钥,钥匙号 DPPPPPPP,建立于 2015-03-16
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
[已吊销] (1). yy_test1 (yy_email_gpg)
未知 (2). [yy]yy Ming Xiao (DSC security)
5、设置新生成的标识的信任关系:
gpg> trust
pub 4096R/DPPPPPPP 创建于:2015-03-16 有效至:2016-03-15 可用于:SC
信任度:绝对 有效性:绝对
sub 4096R/PDDDDDDD 创建于:2015-03-16 有效至:2016-03-15 可用于:E
未知 (1). [yy]yy Ming Xiao (DSC security)
您是否相信这位用户有能力验证其他用户密钥的有效性(查对身份证、通过不同的渠道检查
指纹等)?
1 = 我不知道或我不作答
2 = 我不相信
3 = 我勉强相信
4 = 我完全相信
5 = 我绝对相信
m = 回到主菜单
您的决定是什么? 5
您真的要把这把密钥设成绝对信任?(y/N) y
设置完成后,前面的“未知 (1).”将变为“绝对 (1).”,这一般要先进行save操作后再次进行list可查看到。
6、针对修改进行保存,使用save命令即可。
gpg> save
随意转载~但请保留教程地址★