RSA公钥格式 [英] RSA Public Key format

查看:161
本文介绍了RSA公钥格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到有关RSA公钥格式的文档?



OpenSSH




SSH-RSA AAAAB3NzaC1yc2EAAAABJQAAAQB / nAmOjTmezNUDKYvEeIRf2YnwM9 / uUG1d0BYsc8 / tRtx + RGi7N2lUbp728MXGwdnL9od4cItzky / zVdLZE2cycOa18xBK9cOWmcKS0A8FYBxEQWJ / q9YVUgZbFKfYGaGQxsER + A0w / fX8ALuk78ktP31K69LcQgxIsl7rNzxsoOQKJ / CIxOGMMxczYTiEoLvQhapFQMs3FL96didKr / QbrfB1WT6s3838SEaXfgZvLef1YB2xmfhbT9OXFE3FXvh2UPBfN + ffE7iiayQf / 2XR + 8j4N4bW30DiPtOQLGUrH1y5X / rpNZNlWW2 + jGIxqZtgWg7lTy3mXy5x836Sj / 6L


同样的公钥格式化用于安全Shell (RFC 4716 - 安全Shell(SSH)公钥文件格式)

  ---- BEGIN SSH2 PUBLIC KEY ---- 
AAAAB3NzaC1yc2EAAAABJQAAAQB / nAmOjTmezNUDKYvEeIRf2YnwM9 / uUG1d0BYs
C8 / tRtx + RGi7N2lUbp728MXGwdnL9od4cItzky / zVdLZE2cycOa18xBK9cOWmcKS
0A8FYBxEQWJ / q9YVUgZbFKfYGaGQxsER + A 0瓦特/ fX8ALuk78ktP31K69LcQgxIsl7r
NzxsoOQKJ / CIxOGMMxczYTiEoLvQhapFQMs3FL96didKr / QbrfB1WT6s3838SEaX
fgZvLef1YB2xmfhbT9OXFE3FXvh2UPBfN + ffE7iiayQf / 2XR + 8j4N4bW30DiPtOQ
LGUrH1y5X / rpNZNlWW2 + jGIxqZtgWg7lTy3mXy5x836Sj / 6L
---- END SSH2 PUBLIC KEY ----

与RSA公钥格式相同的公钥(注意 - ,没有空格):

  ----- BEGIN RSA公钥----- 
MIIBCgKCAQEA + XGZ / wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu
ERwta7 + fWIfxOo208ett / jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi / 2A
+ xTBtWdEo7XGUujKDvC2 / aZKukfjpOiUI8AhLAfjmlcD / UZ1QPh0mHsglRNCmpCw
mwSXA9VNmhz +的PiB + Dml4WWnKW / VHo2ujTXxq7 + efMU4H2fny3Se3KYOsFPFGZ1TN
QSYlFuShWrHPtiLmUdPoP6CV2mML1tk + l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P
+ 0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB
----- END RSA公钥-----

基础64编码数据的十六进制转储:

  00 00 00 07 73 73 68 2d 72 73 61 00 00 00 01 25 00 00 01 00 7f 9c 09 
8e 8d 39 9e cc d5 03 29 8b c4 78 84 5f d9 89 f0 33 df ee 50 6d 5d d0
16 2c 73 cf ed 46 dc 7e 44 68 bb 37 69 54 6e 9e f6 f0 c5 c6 c1 d9 cb
f6 87 78 70 8b 73 93 2f f3 55 d2 d9 13 67 32 70 e6 b5 f3 10 4a f5 c3
96 99 c2 92 d0 0f 05 60 1c 44 41 62 7f ab d6 15 52 06 5b 14 a7 d8 19
a1 90 c6 c1 11 f8 0d 30 fd f5 fc 00 bb a4 ef c9 2d 3f 7d 4a eb d2 dc
42 0c 48 b2 5e eb 37 3c 6c a0 e4 0a 27 f0 88 c4 e1 8c 33 17 33 61 38
84 a0 bb d0 85 aa 45 40 cb 37 14 bf 7a 76 27 4a af f4 1b ad f0 75 59
3e ac df cd fc 48 46 97 7e 06 6f 2d e7 f5 60 1d b1 99 f8 5b 4f d3 97
14 4d c5 5e f8 76 50 f0 5f 37 e7 df 13 b8 a2 6b 24 1f ff 65 d1 fb c8
f8 37 86 d6 df 40 e2 3e d3 90 2c 65 2b 1f 5c b9 5f fa e9 35 93 65 59
6d be 8c 62 31 a9 9b 60 5a 0e e5 4f 2d e6 5f 2e 71 f3 7e 92 8f fe 8b

我有 r有几种格式


密钥数据可能以三种一般方式编码:




  • 二进制DER编码格式。这有时被称为ASN.1 BER编码的

  • PEM或base64格式。这是与DER编码文件相同的数据,但是它在base64中编码,附加的页眉和页脚线

  • XML格式。


如果是 ASN.1 ,则十六进制



RSA公钥的格式是什么?






另请参见




解决方案

您不能只从更改分隔符---- BEGIN SSH2 PUBLIC KEY - - ----- BEGIN RSA PUBLIC KEY ----- ,并期望c从一种格式转换到另一种格式(这是您在示例中所做的)。



这篇文章对这两种格式都有很好的解释。



您收到 RSA PUBLIC KEY 更接近 PUBLIC KEY 的内容,但您需要抵消开始的ASN.1结构,以反映这样一个事实,即 PUBLIC KEY 还有一个指示符表示它的键类型(参见 RFC 3447 )。您可以使用 openssl asn1parse -strparse 19 查看此内容,如这个答案



编辑:在您编辑之后,您可以获得您的 RSA PUBLIC KEY 结构的详细信息,使用 grep -v - ----- | tr -d'\\\
'| base64 -d | openssl asn1parse -inform DER

  0:d = 0 hl = 4 l = 266 cons: SEQUENCE 
4:D = 1个HL = 4,L = 257拘谨:INTEGER:FB1199FF0733F6E805A4FD3B36CA68E94D7B974621162169C71538A539372E27F3F51DF3B08B2E111C2D6BBF9F5887F13A8DB4F1EB6DFE386C92256875212DDD00468785C18A9C96A292B067DDC71DA0D564000B8BFD80FB14C1B56744A3B5C652E8CA0EF0B6FDA64ABA47E3A4E89423C0212C07E39A5703FD467540F874987B209513429A90B09B049703D54D9A1CFE3E207E0E69785969CA5BF547A36BA34D7C6AEFE79F314E07D9F9F2DD27B72983AC14F1466754CD41262516E4A15AB1CFB622E651D3E83FA095DA630BD6D93E97B0C822A5EB4212D428300278CE6BA0CC7490B854581F0FFB4BA3D4236534DE09459942EF115FAA231B15153D67837A63
265:D = 1个HL = 2 L = 3拘谨:INTEGER:010001

要解码SSH密钥格式,您需要使用 RFC 4251 ,结合RFC 4253:




 ssh-rsa密钥格式具有以下特定编码:

stringssh-rsa
mpint e
mpint n


例如,在开始,你得到 00 00 00 07 73 73 68 2d 72 73 61 。前四个字节( 00 00 00 07 )给你的长度。其余的是字符串本身:73 = s,68 = h,... - > 73 73 68 2d 72 73 61 = ssh-rsa ,后跟长度为1的指数( 00 00 00 01 25 )和长度256的模数( 00 00 01 00 7f ... )。


Where can i find some documentation on the format of an RSA public key?

An RSA public key formatted by OpenSSH:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQB/nAmOjTmezNUDKYvEeIRf2YnwM9/uUG1d0BYsc8/tRtx+RGi7N2lUbp728MXGwdnL9od4cItzky/zVdLZE2cycOa18xBK9cOWmcKS0A8FYBxEQWJ/q9YVUgZbFKfYGaGQxsER+A0w/fX8ALuk78ktP31K69LcQgxIsl7rNzxsoOQKJ/CIxOGMMxczYTiEoLvQhapFQMs3FL96didKr/QbrfB1WT6s3838SEaXfgZvLef1YB2xmfhbT9OXFE3FXvh2UPBfN+ffE7iiayQf/2XR+8j4N4bW30DiPtOQLGUrH1y5X/rpNZNlWW2+jGIxqZtgWg7lTy3mXy5x836Sj/6L

The same public key formatted for use in Secure Shell (RFC 4716 - The Secure Shell (SSH) Public Key File Format):

---- BEGIN SSH2 PUBLIC KEY ----
AAAAB3NzaC1yc2EAAAABJQAAAQB/nAmOjTmezNUDKYvEeIRf2YnwM9/uUG1d0BYs
c8/tRtx+RGi7N2lUbp728MXGwdnL9od4cItzky/zVdLZE2cycOa18xBK9cOWmcKS
0A8FYBxEQWJ/q9YVUgZbFKfYGaGQxsER+A0w/fX8ALuk78ktP31K69LcQgxIsl7r
NzxsoOQKJ/CIxOGMMxczYTiEoLvQhapFQMs3FL96didKr/QbrfB1WT6s3838SEaX
fgZvLef1YB2xmfhbT9OXFE3FXvh2UPBfN+ffE7iiayQf/2XR+8j4N4bW30DiPtOQ
LGUrH1y5X/rpNZNlWW2+jGIxqZtgWg7lTy3mXy5x836Sj/6L
---- END SSH2 PUBLIC KEY ----

The same public key formatted as an RSA public key (note the five -, and no space):

-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu
ERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A
+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw
mwSXA9VNmhz+PiB+Dml4WWnKW/VHo2ujTXxq7+efMU4H2fny3Se3KYOsFPFGZ1TN
QSYlFuShWrHPtiLmUdPoP6CV2mML1tk+l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P
+0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB
-----END RSA PUBLIC KEY-----

The hex dump of the base-64 encoded data:

00 00 00 07 73 73 68 2d 72 73 61 00 00 00 01 25 00 00 01 00 7f 9c 09
8e 8d 39 9e cc d5 03 29 8b c4 78 84 5f d9 89 f0 33 df ee 50 6d 5d d0 
16 2c 73 cf ed 46 dc 7e 44 68 bb 37 69 54 6e 9e f6 f0 c5 c6 c1 d9 cb
f6 87 78 70 8b 73 93 2f f3 55 d2 d9 13 67 32 70 e6 b5 f3 10 4a f5 c3 
96 99 c2 92 d0 0f 05 60 1c 44 41 62 7f ab d6 15 52 06 5b 14 a7 d8 19 
a1 90 c6 c1 11 f8 0d 30 fd f5 fc 00 bb a4 ef c9 2d 3f 7d 4a eb d2 dc 
42 0c 48 b2 5e eb 37 3c 6c a0 e4 0a 27 f0 88 c4 e1 8c 33 17 33 61 38 
84 a0 bb d0 85 aa 45 40 cb 37 14 bf 7a 76 27 4a af f4 1b ad f0 75 59 
3e ac df cd fc 48 46 97 7e 06 6f 2d e7 f5 60 1d b1 99 f8 5b 4f d3 97 
14 4d c5 5e f8 76 50 f0 5f 37 e7 df 13 b8 a2 6b 24 1f ff 65 d1 fb c8 
f8 37 86 d6 df 40 e2 3e d3 90 2c 65 2b 1f 5c b9 5f fa e9 35 93 65 59 
6d be 8c 62 31 a9 9b 60 5a 0e e5 4f 2d e6 5f 2e 71 f3 7e 92 8f fe 8b

i've read that there are a couple of formats:

Key data may be encoded in three general ways:

  • Binary DER-encoded format. This is sometimes called ASN.1 BER-encoded
  • PEM or base64 format. This is the same data as the DER-encoded file but it is encoded in base64 with additional header and footer lines
  • XML format.

If it's ASN.1, the hex certainly doesn't look like it.

What's the format of an RSA public key?


See also

解决方案

You can't just change the delimiters from ---- BEGIN SSH2 PUBLIC KEY ---- to -----BEGIN RSA PUBLIC KEY----- and expect that it will be sufficient to convert from one format to another (which is what you've done in your example).

This article has a good explanation about both formats.

What you get in an RSA PUBLIC KEY is closer to the content of a PUBLIC KEY, but you need to offset the start of your ASN.1 structure to reflect the fact that PUBLIC KEY also has an indicator saying which type of key it is (see RFC 3447). You can see this using openssl asn1parse and -strparse 19, as described in this answer.

EDIT: Following your edit, your can get the details of your RSA PUBLIC KEY structure using grep -v -- ----- | tr -d '\n' | base64 -d | openssl asn1parse -inform DER:

    0:d=0  hl=4 l= 266 cons: SEQUENCE          
    4:d=1  hl=4 l= 257 prim: INTEGER           :FB1199FF0733F6E805A4FD3B36CA68E94D7B974621162169C71538A539372E27F3F51DF3B08B2E111C2D6BBF9F5887F13A8DB4F1EB6DFE386C92256875212DDD00468785C18A9C96A292B067DDC71DA0D564000B8BFD80FB14C1B56744A3B5C652E8CA0EF0B6FDA64ABA47E3A4E89423C0212C07E39A5703FD467540F874987B209513429A90B09B049703D54D9A1CFE3E207E0E69785969CA5BF547A36BA34D7C6AEFE79F314E07D9F9F2DD27B72983AC14F1466754CD41262516E4A15AB1CFB622E651D3E83FA095DA630BD6D93E97B0C822A5EB4212D428300278CE6BA0CC7490B854581F0FFB4BA3D4236534DE09459942EF115FAA231B15153D67837A63
  265:d=1  hl=2 l=   3 prim: INTEGER           :010001

To decode the SSH key format, you need to use the data format specification in RFC 4251 too, in conjunction with RFC 4253:

   The "ssh-rsa" key format has the following specific encoding:

      string    "ssh-rsa"
      mpint     e
      mpint     n

For example, at the beginning, you get 00 00 00 07 73 73 68 2d 72 73 61. The first four bytes (00 00 00 07) give you the length. The rest is the string itself: 73=s, 68=h, ... -> 73 73 68 2d 72 73 61=ssh-rsa, followed by the exponent of length 1 (00 00 00 01 25) and the modulus of length 256 (00 00 01 00 7f ...).

这篇关于RSA公钥格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆