首页 » 信息技术 »

用openssl读取私钥内容

2019年5月22日 / 30次阅读
加密解密

一点点学习openssl这个工具的使用,本文总结读取公钥私钥内容的命令格式。

用openssl读取私钥,使用openssl rsa -in private.key命令,读取公钥的命令,可以考虑直接使用cat。

生成私钥:

openssl genrsa 1024 > private.key

读取私钥内容:

使用cat private.key是可以读取私钥内容的,不过这里我们使用openssl这个工具来读取。

xinlin@ubuntuserver:~/test$ openssl rsa -in private.key
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDy5thpdSk0KnDuVL3eb7vEjEHLPMiG3ewSCFCEl5Fmkma2TgAY
nM7wye8LarhY3sGzmEoZ2nfCNlaimiMKQlj97hholsMRU2Fuq+AoOmaGgrzFVQxU
LhKhDAByNHaCud7P5cL+cEfy/3TOUZSpOHLTAnnJPgXXBLBneXHEhm8XzwIDAQAB
AoGBAKYwKOrmPR2y1/dIRWu12KseJznNSYl0trqTs7s0FEgwbFPYxBoS10dJceLG
zoAHUFH3JOPRZFSdZuLzQHwZbtZgXUZQqOEsjcOeyjlps8gC7XIWY/ltcCyTZKsr
5gQuK4vMfXRLcHX7Z/E/yEPWI7A32e+W+75oaYC/7/FD7JxxAkEA+/FHjYMwQSxJ
jqtgBRaxF3F4mYllq4FU4JbrnAWzRWGFvXgJ0Dko6NG3nUSnlCZo48JeXiKtc6OY
vwDSqkhu2QJBAPbQSszWkOvY2OFQ/CP+kC2el8VcEzrgwnx3Saan4cldm95w/I5a
xbRVoeM6jwZkmN7YcX9xlbBQk4DHY2tEYucCQHAsFfqIrWRnDn0KCl9ZohFZASQD
C5RXqe2w5Ef8NbwvVndsSZo+yNsX/JN17NLGYy787D0nXWi+LxTjjegpBckCQQCB
dAKnqardaSFoHJgDMRPiOZqVM5QKf7TCn7aLqOZuPaDxbQWqjMXBrmB41FAMJFti
FtiA5cyDa9/R3cKxkm7lAkACeVnk8ot9992qPyZMfwQGYtuxmZAlJEhuT583mI6b
l1Y1GEY6+wdtNK2fZWm6C0p9998KlhrvKINT/0SLKSLD
-----END RSA PRIVATE KEY-----

以纯文本的方式读取私钥内容:

xinlin@ubuntuserver:~/test$ openssl rsa -in private.key -text
Private-Key: (1024 bit)
modulus:
00:f2:e6:d8:69:75:29:34:2a:70:ee:54:bd:de:6f:
bb:c4:8c:41:cb:3c:c8:86:dd:ec:12:08:50:84:97:
91:66:92:66:b6:4e:00:18:9c:ce:f0:c9:ef:0b:6a:
b8:58:de:c1:b3:98:4a:19:da:77:c2:36:56:a2:9a:
23:0a:42:58:fd:ee:18:68:96:c3:11:53:61:6e:ab:
e0:28:3a:66:86:82:bc:c5:55:0c:54:2e:12:a1:0c:
00:72:34:76:82:b9:de:cf:e5:c2:fe:70:47:f2:ff:
74:ce:51:94:a9:38:72:d3:02:79:c9:3e:05:d7:04:
b0:67:79:71:c4:86:6f:17:cf
publicExponent: 65537 (0x10001)
privateExponent:
00:a6:30:28:ea:e6:3d:1d:b2:d7:f7:48:45:6b:b5:
d8:ab:1e:27:39:cd:49:89:74:b6:ba:93:b3:bb:34:
14:48:30:6c:53:d8:c4:1a:12:d7:47:49:71:e2:c6:
ce:80:07:50:51:f7:24:e3:d1:64:54:9d:66:e2:f3:
40:7c:19:6e:d6:60:5d:46:50:a8:e1:2c:8d:c3:9e:
ca:39:69:b3:c8:02:ed:72:16:63:f9:6d:70:2c:93:
64:ab:2b:e6:04:2e:2b:8b:cc:7d:74:4b:70:75:fb:
67:f1:3f:c8:43:d6:23:b0:37:d9:ef:96:fb:be:68:
69:80:bf:ef:f1:43:ec:9c:71
prime1:
00:fb:f1:47:8d:83:30:41:2c:49:8e:ab:60:05:16:
b1:17:71:78:99:89:65:ab:81:54:e0:96:eb:9c:05:
b3:45:61:85:bd:78:09:d0:39:28:e8:d1:b7:9d:44:
a7:94:26:68:e3:c2:5e:5e:22:ad:73:a3:98:bf:00:
d2:aa:48:6e:d9
prime2:
00:f6:d0:4a:cc:d6:90:eb:d8:d8:e1:50:fc:23:fe:
90:2d:9e:97:c5:5c:13:3a:e0:c2:7c:77:49:a6:a7:
e1:c9:5d:9b:de:70:fc:8e:5a:c5:b4:55:a1:e3:3a:
8f:06:64:98:de:d8:71:7f:71:95:b0:50:93:80:c7:
63:6b:44:62:e7
exponent1:
70:2c:15:fa:88:ad:64:67:0e:7d:0a:0a:5f:59:a2:
11:59:01:24:03:0b:94:57:a9:ed:b0:e4:47:fc:35:
bc:2f:56:77:6c:49:9a:3e:c8:db:17:fc:93:75:ec:
d2:c6:63:2e:fc:ec:3d:27:5d:68:be:2f:14:e3:8d:
e8:29:05:c9
exponent2:
00:81:74:02:a7:a9:aa:dd:69:21:68:1c:98:03:31:
13:e2:39:9a:95:33:94:0a:7f:b4:c2:9f:b6:8b:a8:
e6:6e:3d:a0:f1:6d:05:aa:8c:c5:c1:ae:60:78:d4:
50:0c:24:5b:62:16:d8:80:e5:cc:83:6b:df:d1:dd:
c2:b1:92:6e:e5
coefficient:
02:79:59:e4:f2:8b:7d:f7:dd:aa:3f:26:4c:7f:04:
06:62:db:b1:99:90:25:24:48:6e:4f:9f:37:98:8e:
9b:97:56:35:18:46:3a:fb:07:6d:34:ad:9f:65:69:
ba:0b:4a:7d:f7:df:0a:96:1a:ef:28:83:53:ff:44:
8b:29:22:c3
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDy5thpdSk0KnDuVL3eb7vEjEHLPMiG3ewSCFCEl5Fmkma2TgAY
nM7wye8LarhY3sGzmEoZ2nfCNlaimiMKQlj97hholsMRU2Fuq+AoOmaGgrzFVQxU
LhKhDAByNHaCud7P5cL+cEfy/3TOUZSpOHLTAnnJPgXXBLBneXHEhm8XzwIDAQAB
AoGBAKYwKOrmPR2y1/dIRWu12KseJznNSYl0trqTs7s0FEgwbFPYxBoS10dJceLG
zoAHUFH3JOPRZFSdZuLzQHwZbtZgXUZQqOEsjcOeyjlps8gC7XIWY/ltcCyTZKsr
5gQuK4vMfXRLcHX7Z/E/yEPWI7A32e+W+75oaYC/7/FD7JxxAkEA+/FHjYMwQSxJ
jqtgBRaxF3F4mYllq4FU4JbrnAWzRWGFvXgJ0Dko6NG3nUSnlCZo48JeXiKtc6OY
vwDSqkhu2QJBAPbQSszWkOvY2OFQ/CP+kC2el8VcEzrgwnx3Saan4cldm95w/I5a
xbRVoeM6jwZkmN7YcX9xlbBQk4DHY2tEYucCQHAsFfqIrWRnDn0KCl9ZohFZASQD
C5RXqe2w5Ef8NbwvVndsSZo+yNsX/JN17NLGYy787D0nXWi+LxTjjegpBckCQQCB
dAKnqardaSFoHJgDMRPiOZqVM5QKf7TCn7aLqOZuPaDxbQWqjMXBrmB41FAMJFti
FtiA5cyDa9/R3cKxkm7lAkACeVnk8ot9992qPyZMfwQGYtuxmZAlJEhuT583mI6b
l1Y1GEY6+wdtNK2fZWm6C0p9998KlhrvKINT/0SLKSLD
-----END RSA PRIVATE KEY-----

如果在刚才的命令上再加上-noout这个参数,将指挥显示text格式的私钥内容,后面这段是用Base64编码之后的私钥内容。

而公钥不能通过openssl rsa -in这个命令读取,可以直接使用cat命令。

本文链接:https://www.maixj.net/ict/openssl-dukey-21474

相关文章

留言区


前一篇:
后一篇:

栏目精选

云上小悟,麦新杰的独立博客

Ctrl+D 收藏本页

栏目


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top