前一篇:基础练习: 使用openssl命令创建RSA密钥
除了openssl之外, 还有好几种工具也可以生成RSA密钥文件, 包括OpenSSH的ssh-keygen
,GnuPG的gpg
等等.
其中 ssh-keygen 输出的RSA密钥文件的版本较旧, 这种比较旧文件格式不同于PKCS#8标准. 但是openssl支持这种旧版密钥格式.
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC, 一串十六进制数字作为初始向量
……(Base64格式的内容)……
-----END RSA PRIVATE KEY-----
调用ssh-keygen
命令可以RSA密钥文件~/.ssh/id_rsa
,屏幕输出的内容为:
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/liuqun/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): \*\*\*\*\*\*
Enter same passphrase again: \*\*\*\*\*\*
Your identification has been saved in /home/liuqun/.ssh/id_rsa.
Your public key has been saved in /home/liuqun/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RdaoCVtF8L/kMR3GlCTC4fcCqpIVmmdrFihOI01/wqs liuqun@suse
The key's randomart image is:
+---[RSA 2048]----+
| .=B+..o. |
| . .=o..+. |
| . .+ o= . + |
| o o +..oo + + . |
|. = B \* S \* o |
| + o O + o = |
| . + = o |
| . + |
| E |
+----[SHA256]-----+
生成的私钥为
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,1C2BAB04530F6C1CAD659D271960EA75
gt3xwAT9ubiswCujn+jT3YBYM2N3+sAIZXd+SUV7dw+2ZQkgJ69lHS9DIRCid/zG
…若干行…
-----END RSA PRIVATE KEY-----
openssl的子命令rsa可以解读由ssh-keygen
输出的密钥文件,屏幕输出格式与之前一致
openssl rsa -in ~/.ssh/id_rsa -text -noout
输出:
Enter pass phrase for id_rsa:
Private-Key: (2048 bit)
modulus:
00:bc:56:6d:f2:46:a2:9a:f5:2d:0d:24:e0:82:2c …省略…
publicExponent: 65537 (0x10001)
privateExponent:
21:18:1e:e1:bf:bf:ba:f2:f2:23:a9:23:3a:3c:7c …省略…
prime1:
00:e2:16:5c:e4:bb:1e:e4:c3:43:a6:0a:c5:0b:d6 …省略…
prime2:
00:d5:41:79:21:c0:94:ef:32:b2:3c:85:96:b6:da …省略…
exponent1:
…省略…
exponent2:
…省略…
coefficient:
…省略…
ssh-keygen输出的公钥是一个长行, ~/.ssh/id_rsa.pub 的内容是:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8Vm3yRqKa9S0NJOCCLBKswcQGFHsVksK+k3ZCoSOuW/8y+sUVoAOzjpkKTaltzknU7l91MvdBeT7thlFZ91jxOQkj9RRsBZKiJ+/LJnH329qPQB5UFjCYFKhDIiJgas6oQs6XIwRKWVZjW3+iNNq4WxofDO+T/mz4Tw5ZVv5knQrdX4b5MnVEucpmHY+Kyih1DFGLMUd3Du7u+k0zb2HFSjHfen9MnWTZelrhSI1gSoDJITzhPOTcHhCg+VkEb0kSIQPSpqcU0VcRzNZ/eLaKXgDZ1aLKDaaQi89x+3CluxcIKHGwdNwm6dUl/tWOabryyxvpyH5vQae4mx40PAwJ liuqun@suse