补上一课,RSA命令行生成不同格式的秘钥。
RSA秘钥分为PKCS#8和PKCS#1
1.生成PEM格式的私钥,默认格式是PKCS#1
openssl genrsa -out private.pem 2048
PKCS#1记住格式的关键词 Begin RSA private key + End RSA private key
2.由私钥推出公钥
openssl rsa -in private.pem -pubout -out public.pem
PKCS#1转为为PKCS#8格式,使用命令行:openssl pkcs8 -topk8 -inform PEM -in private.pem -outform PEM -nocrypt > private_pkcs8.pem
PKCS#8记住格式的关键词 Begin private key + End private key
转为为PKCS#1格式,使用命令行:
3.查看私钥内部的模数指数
openssl rsa -in private.pem 2048 -text -noout
第三步运行的结果如下所示:
RSA Private-Key: (2048 bit, 2 primes)
modulus:
00:b6:1f:1f:62:6b:44:cf:ab:7a:f9:87:87:58:96:
fb:f4:a4:41:fd:7a:7e:ae:1a:e2:0f:b0:7d:5c:d7:
72:8f:84:17:97:72:ce:c0:27:5d:76:cf:2c:f0:4e:
ea:12:72:3c:35:5d:50:3d:4d:cd:d5:a2:b3:cd:61:
ba:22:53:03:db:b1:92:10:fe:29:b5:9f:89:f5:f8:
4f:d9:2c:2f:8d:f5:34:dc:69:09:b2:42:34:2c:cc:
0d:d4:57:1c:d3:46:d3:b6:70:52:28:0b:e7:39:7a:
d1:c6:7e:59:ee:cf:38:94:cc:fe:05:b4:5d:98:b4:
b4:f4:f8:5d:b3:76:4b:ef:7d:10:9b:36:30:ea:63:
75:cd:12:c8:87:bc:47:82:1a:4f:6f:fe:17:58:8d:
95:99:81:6b:5a:10:5d:5b:cc:0e:01:ec:16:85:9f:
ad:a4:9e:c4:04:5d:43:55:a8:19:46:47:09:d5:48:
d3:06:43:e8:26:f9:a2:0b:7d:72:0e:4b:76:13:47:
02:19:e8:75:44:55:0c:36:b7:97:2f:8f:6e:07:72:
85:34:1f:59:bb:33:57:c2:84:ec:cb:30:14:02:79:
8e:1e:bb:26:7b:cc:04:f2:44:8c:ea:85:8d:39:b9:
83:3b:7d:37:74:d7:6e:fe:57:4c:51:d7:d2:f5:07:
4f:01
publicExponent: 65537 (0x10001)
privateExponent:
3b:50:27:88:86:27:02:fb:76:31:8e:52:26:28:06:
26:c6:d8:37:15:8d:ec:66:14:f9:c7:21:0c:fb:9d:
f3:df:b1:4f:41:b4:d4:1f:fd:f0:93:c8:ae:fb:04:
80:bd:73:9e:6d:a5:94:51:a2:97:d1:45:7d:be:36:
40:b7:88:aa:24:4a:cd:fd:f8:d7:8d:fe:00:7d:be:
83:9c:40:60:9b:5b:7b:ed:39:9b:34:b4:89:62:6b:
9e:9c:40:67:0e:ca:24:c0:b0:01:1a:df:53:79:0c:
98:f8:cd:91:59:2b:b4:4a:8e:f0:8c:ad:6e:ee:6b:
80:dc:e2:a7:6f:ff:8b:1f:43:82:c6:96:f9:d5:ed:
24:e9:46:a4:17:7d:c1:1b:35:38:a4:e6:9f:6a:bb:
76:a7:53:8e:3b:60:65:38:ea:bf:1d:28:57:8d:1e:
17:ed:e0:94:71:3d:80:5b:9c:ea:95:97:9b:fa:0b:
12:3c:fc:75:b0:88:54:f5:b1:e4:b9:33:11:d4:82:
fe:76:5c:eb:1c:c9:79:9e:9a:56:db:eb:49:01:61:
e7:83:bc:f8:dd:32:18:8b:c2:03:42:e8:0c:f2:dc:
ce:84:d4:ea:38:d7:cf:af:cc:bb:49:c0:68:cc:32:
c6:47:57:85:8c:1a:9e:13:7c:03:40:ca:c0:6b:a5:
81
prime1:
00:d6:2a:75:01:c3:d0:27:f5:ed:1f:a6:b7:cd:13:
61:f2:2f:ee:f0:43:1a:a4:c0:b7:2f:1e:e8:9e:0a:
6f:55:37:1e:a1:8e:e5:92:f1:ec:48:a4:37:b1:ec:
8a:f1:5a:d8:07:0d:0a:39:f3:c5:c5:ce:ff:53:8c:
e9:df:fe:be:8f:01:63:d5:86:bf:05:27:5f:0a:77:
13:df:2b:9b:97:2d:20:ba:f5:e5:d8:31:5e:bf:f1:
99:9b:97:2e:30:ab:f2:7d:e1:c1:21:2f:57:0f:21:
37:93:e1:af:be:b6:4e:b1:76:cd:5e:74:74:d8:48:
51:92:72:e1:30:44:06:2b:47
prime2:
00:d9:b2:43:c0:fe:1e:ed:2e:c5:2f:6f:6e:c5:5d:
26:3f:d7:bb:e0:07:0a:38:fc:73:5f:48:68:d1:bb:
c1:db:0b:f4:84:11:56:0d:f8:ca:5e:2d:a7:76:b7:
7e:4a:c5:99:34:15:2d:a0:37:a0:1d:e5:d4:b7:97:
8c:32:2c:f8:77:a2:1b:ba:5b:34:9f:b0:08:f3:47:
69:23:fd:ed:ac:30:e8:7e:e8:f3:99:60:10:b8:2d:
d3:96:1b:c4:ba:14:92:d8:2f:86:11:c8:a5:4b:af:
f3:af:35:da:d9:09:99:50:34:0f:d3:79:3d:bd:bc:
c3:03:ac:56:cd:a9:d3:c7:77
exponent1:
4e:46:6c:47:7d:db:09:8f:ef:df:de:9e:54:fc:dd:
92:98:04:5b:9a:1b:15:d6:3d:dd:a2:0d:61:1d:ed:
3d:17:0d:41:fd:29:59:40:c4:9c:74:30:ca:fd:ea:
76:76:3e:78:ad:42:6c:95:f5:55:eb:e7:14:11:6f:
b5:67:b5:1c:2d:64:e0:b9:03:fe:0d:3a:c6:67:69:
42:ea:fc:4e:0f:b7:63:bd:d6:08:e3:5a:7f:0a:fd:
9a:89:71:df:66:29:15:eb:3a:1c:37:e2:38:ec:6a:
14:c9:aa:e3:28:5c:b0:ad:fc:37:a6:96:c2:2a:04:
6e:63:40:7c:d4:8f:f0:a7
exponent2:
6d:d0:29:b3:59:bc:fa:02:04:bf:d7:e3:35:b5:b6:
4c:b0:23:7a:6f:b2:ad:6a:53:3c:76:47:41:bd:07:
9d:da:5a:fe:9f:cc:1c:02:2a:fa:f4:e6:ab:d1:05:
e8:eb:e2:4b:4e:7f:94:79:5a:d0:9a:16:02:82:74:
da:fe:aa:5b:96:af:8c:02:e3:f9:c5:8f:ce:40:70:
7e:12:62:68:e0:c6:f6:f5:c5:a3:d1:bc:bd:5b:88:
87:08:fc:e4:ac:ea:22:19:5e:f4:eb:94:ce:28:34:
b1:66:66:3d:e3:44:ae:1b:84:fc:35:05:7b:07:94:
0b:ef:4c:5e:34:53:bb:23
coefficient:
1c:aa:ea:19:d3:32:6a:9f:ac:ba:73:60:2e:c5:43:
6a:7b:7b:39:f5:0a:3f:02:fd:6d:d0:2f:67:0e:2f:
a5:84:b3:f4:85:84:0b:f0:fd:ff:28:d6:3b:df:1f:
76:af:49:ae:96:04:1d:53:21:8f:14:00:f6:31:6c:
f7:27:ec:87:ea:e8:59:7d:42:18:b3:10:29:cc:8a:
53:fa:e5:6e:11:71:5f:2b:c8:5d:0f:15:7b:2b:13:
74:8d:c5:92:74:a9:4b:2e:6b:da:10:38:af:18:83:
a5:b1:e0:42:f6:49:da:09:19:ab:14:9d:b8:34:a0:
1a:eb:21:5b:ef:08:23:fa
第三步完因为是查看方式,所以没办法保存下来,但是我们可以通过copy paste方式将秘钥内部的所有参数都保存到本地文件中。这种格式的秘钥主要是方便一些嵌入式设备使用到Openssl的秘钥,方便快捷。
可以看到
RSA 描述的私钥的结构如下(其中除 n,d 之外的都是冗余信息):
-
modulus
: 模数 n -
publicExponent
: 公指数 e,固定为 65537 (0x10001) -
privateExponent
: 私钥指数 d -
prime1
: 质数 p,用于计算 n -
prime2
: 质数 q,用于计算 n -
exponent1
: 用于加速 RSA 运算的中国剩余定理指数一,d mod(p−1) -
exponent2
: 用于加速 RSA 运算的中国剩余定理指数二,d mod(q−1) -
coefficient
: 用于加速 RSA 运算的中国剩余定理系数,q−1 mod p
再看下 RSA 公钥的结构:文章来源:https://www.toymoban.com/news/detail-843172.html
-
modulus
: 模数 n -
exponent
: 公指数 e,固定为 65537 (0x10001)
一般嵌入式中只需要公私钥都只使用到模数和指数,其他一些参数在RSA算法中使用方式有待探索。文章来源地址https://www.toymoban.com/news/detail-843172.html
到了这里,关于Openssl入门第六课--RSA命令行生成秘钥的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!