下载PGP签名工具GnuPG并生成相应的秘钥,pgp签名工具gnupg
下载PGP签名工具GnuPG并生成相应的秘钥,pgp签名工具gnupg
- 资源链接
- GnuPG的使用
- 验证GnuPG是否安装成功
- 生成一个密钥对
- 查看我们生成的秘钥
- 查看秘钥
- 查看私有密匙
如果我们想将自己的Maven项目发布到Maven的中央仓库中,那么我们得学会使用PGP签名,因为Maven为了提高整体构建的平水,因而引入了PGP签名机制。
资源链接
PGP签名的官方文档如下:
- Working with PGP Signatures
PGP的官方下载地址如下:
- GnuPG Download
GnuPG支持多个操作系统,大家可以选择合适的去下载,由于我这里选择的是windows操作系统,因而我就以该系统的对应软件版本为例来进行说明。
在官网上提供的下载地址其实是付费的,但是也有免费版,虽说这些版本不是最新版,但是至少也能用,下面的GnuPG以往的历史版本的下载地址:
- gpg4win
当然也可以访问我的码云,在码云上已经上传了两个不同版本的GnuPG,这个大家可以自行选择使用,下载链接如下:
- 码云 GnuPG
在这里,我使用的版本为:
- gpg4win-2.3.4
GnuPG的使用
安装该软件我就不用细说了,该软件的安装方式其实是和其它的应用软件安装方式是一样的,所以说对于它的安装我就不用说明了。
验证GnuPG是否安装成功
在GnuPG安装完成后,我们可以通过下面的指令来判断该软件是否安装成功,比如说我们可以查看该软件所生成的版本号,此时我们在命令行中敲入以下指令:
gpg --version
此时在命令行中显示的结果为:
C:\Users\Administrator>gpg --version
gpg (GnuPG) 2.0.30 (Gpg4win 2.3.4)
libgcrypt 1.7.8
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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
GnuPG在不同的操作系统中的显示可能不一样,在其它的操作系统中,其查看版本号的指令可能如下:
gpg2 --version
这里我也在命令行中进行了敲入,显示的结果如下:
C:\Users\Administrator>gpg2 --version
gpg (GnuPG) 2.0.30 (Gpg4win 2.3.4)
libgcrypt 1.7.8
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
...
当我们看到上述信息时,这就说明我们的GnuPG软件已经安装成功,此时我们就可以正常使用了。
生成一个密钥对
密钥对允许您使用GPG签署工件,并且用户可以随后验证工件已经由您签署。你可以使用下列命令行生成秘钥。
gpg --gen-key
之后我们会查看到下述信息。
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,点击回车键。
之后我们又将会查看到下述选择信息:
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
这时询问我们是否是类型为(RSA)和键的大小为(2048位),此时我们仍然选用的是默认值,点击回车键。
在接下来我们将会看到下述信息,该信息是询问我们秘钥的有效期,一般情况下,我们选择的秘钥有效期是在2年以内,一旦密钥过期,您就可以扩展它,只要您拥有密钥并因此知道密码。
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)
此时我将秘钥的有效期设置为2周,因而在这里我输入的是“2w”。
之后将询问我们是否确定,信息如下:
Key is valid for? (0) 2w
Key expires at 01/18/18 15:27:38 中国标准时间
Is this correct? (y/N)
这里,我当然是确定了,因而这里我选择的是“y”,然后点击回车。
GnuPG needs to construct a user ID to identify your key.
Real name:
它的意思是说“GnuPG需要构造一个用户ID来标识您的密钥。”,我们在“Real name”处输入自定义的真名,这里,我输入的是“zhangzhenyi”,后面又要求我们输入邮箱账号等信息,下面是我输入的详细信息:
Real name: zhangzhenyi
Email address: 1078689276@qq.com
Comment: this is for maven central
You selected this USER-ID:
"zhangzhenyi (this is for maven central) <1078689276@qq.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
我们可以看到,当上述信息都输入完成之后,GnuPG会询问我们是否变更,此处我们如果想要变更,输入对应的括号内字母即可,如果想退出,直接输入“Q”。此时我们确认信息无误,因而我们输入的字母为“O”。
之后我们会看到下述信息:
You need a Passphrase to protect your secret key.
其意思是“你需要一个密码来保护你的秘密密钥。”于此同时桌面上还弹出一个长长的窗口,如下:
该窗口很容易自己退出,而一旦退出,我们就会看到下面的信息,此时我们就只能重来了。
gpg: cancelled by user
gpg: Key generation canceled.
而我们在输入密码时也并非是想输入啥就输入啥,其必须得符合相应的格式,那就是必须是十位信息,而且该信息必须是字母+(数字或特殊字符),否则的话我们将会看到警告信息,同时之前的操作还得重来。(⊙o⊙)…万恶啊!!!
当我们输入完成后,点击确定按钮之后,接下来出现的是验证密码操作,如果该操作失败,继续重复之前的所有操作,如果输入正确,则我们将会生成自己的秘钥,其验证密码操作界面如下:
当我们验证通过后,其显示的信息如下:
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 1F60EF57 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 2018-01-18
pub 2048R/1F60EF57 2018-01-04 [expires: 2018-01-18]
Key fingerprint = 868A 26F4 A443 5E44 B7E4 6E3F 6396 3441 1F60 EF57
uid [ultimate] zhangzhenyi (this is for maven central) <1078689276@qq.com>
sub 2048R/288F9A04 2018-01-04 [expires: 2018-01-18]
查看我们生成的秘钥
查看秘钥
查看秘钥的指令如下:
gpg2 --list-keys
当我们在命令行中键入该信息时,我们就可以看到我们的秘钥信息了,信息如下:
C:/Users/Administrator/AppData/Roaming/gnupg/pubring.gpg
--------------------------------------------------------
pub 2048R/1F60EF57 2018-01-04 [expires: 2018-01-18]
uid [ultimate] zhangzhenyi (this is for maven central) <1078689276@qq.com>
sub 2048R/288F9A04 2018-01-04 [expires: 2018-01-18]
查看私有密匙
查看私有秘钥的指令如下:
gpg2 --list-secret-keys
私有秘钥的查看结果:
C:/Users/Administrator/AppData/Roaming/gnupg/secring.gpg
--------------------------------------------------------
sec 2048R/1F60EF57 2018-01-04 [expires: 2018-01-18]
uid zhangzhenyi (this is for maven central) <1078689276@qq.com>
ssb 2048R/288F9A04 2018-01-04
好了,至此我们已经成功完成了生成秘钥的全部操作。
版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/ZZY1078689276/article/details/78971292
评论暂时关闭