读取 ASN.1 DER 编码的 RSA 公钥

发布于 2024-08-02 03:36:28 字数 778 浏览 4 评论 0原文

我正在编写一个应用程序来更好地了解 DKIM。 规范说我从域 TXT 记录中检索“ASN.1 DER 编码”公钥。 我可以在“s1024._domainkey.yahoo.com”=“MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm”上看到密钥。

如何使用 .net 中的此密钥? 我见过的示例从 X509Certificate2 或包含 RSAParameters 的 XML 文件获取密钥。

更正:我从 network-tools.com DNS 工具复制/粘贴了上面的密钥,这肯定已经缩短了它。 nslookup 给了我完整的密钥:

s1024._domainkey.yahoo.com 文本 = “k=rsa;t=y;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm” “JiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bTxhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj+XcwIDAQAB;n=A 1024 位密钥;”

所以 abelenky 的 BASE64 走在正确的道路上。

I'm writing an app to get a better understanding of DKIM. The spec says I retrieve a "ASN.1 DER-encoded" public key from the domain TXT record. I can seen the key on "s1024._domainkey.yahoo.com" = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm".

How can I use this key from .net? The examples I've seen get the key from a X509Certificate2, or an XML file containing the RSAParameters.

CORRECTION: I copy/pasted the key above from the network-tools.com DNS tool, which must've cut it short. nslookup gives me the full key:

s1024._domainkey.yahoo.com text =
"k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm"
"JiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bTxhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj+XcwIDAQAB; n=A 1024 bit key;"

So abelenky was on the right track with BASE64..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

森林很绿却致人迷途 2024-08-09 03:36:29

对于任何对此事感兴趣的人,我建议 System.Security .Cryptography.X509Certificates.PublicKey 可用于读取 DER 编码的公钥。

For anyone interested in this matter I would suggest the System.Security.Cryptography.X509Certificates.PublicKey which can be used to read a DER encoded public key.

长亭外,古道边 2024-08-09 03:36:29

该字符串看起来像是某种 Base-64 编码。
如果将该字符串从 base-64 转换为 BLOB,则它应该采用有效的 ASN.1 格式。

That string looks like its some sort of base-64 encoding.
If you convert that string from base-64 to a BLOB, it should then be in valid ASN.1 format.

请远离我 2024-08-09 03:36:29

尝试使用 bouncycastle 库,它为此类情况提供了强大的功能。

Try the bouncycastle library, it provides great functionality for such cases.

很快妥协 2024-08-09 03:36:28

这是包含 RSA 公钥的 ASN.1 PublicKeyInfo 的 DER 编码的 Base64 编码。

翻译如下:

   0 30  159: SEQUENCE {
   3 30   13:   SEQUENCE {
   5 06    9:     OBJECT IDENTIFIER '1 2 840 113549 1 1 1'
  16 05    0:     NULL
            :     }
  18 03  141:   BIT STRING 0 unused bits, encapsulates {
  22 30  137:       SEQUENCE {
  25 02  129:         INTEGER
            :           00 EB 11 E7 B4 46 2E 09 BB 3F 90 7E 25 98 BA 2F
            :           C4 F5 41 92 5D AB BF D8 FF 0B 8E 74 C3 F1 5E 14
            :           9E 7F B6 14 06 55 18 4D E4 2F 6D DB CD EA 14 2D
            :           8B F8 3D E9 5E 07 78 1F 98 98 83 24 E2 94 DC DB
            :           39 2F 82 89 01 45 07 8C 5C 03 79 BB 74 34 FF AC
            :           04 AD 15 29 E4 C0 4C BD 98 AF F4 B7 6D 3F F1 87
            :           2F B5 C6 D8 F8 46 47 55 ED F5 71 4E 7E 7A 2D BE
            :           2E 75 49 F0 BB 12 B8 57 96 F9 3D D3 8A 8F FF 97
            :           73
 157 02    3:         INTEGER 65537
            :         }
            :       }
            :   }

OBJECT IDENTIFIER 表示后面的 BIT STRING 包含 RSAPublicKey 的编码。 INTEGER 是模数和公共指数。

您可以使用 Convert.FromBase64String 解码 Base64,但是我不认为 .NET 具有用于解析 PublicKeyInfos 的内置功能,因此您需要使用像 BouncyCastle 这样的第 3 方工具。

This is the base64-encoding of the DER-encoding of an ASN.1 PublicKeyInfo containing an RSA public key.

Here is a translation:

   0 30  159: SEQUENCE {
   3 30   13:   SEQUENCE {
   5 06    9:     OBJECT IDENTIFIER '1 2 840 113549 1 1 1'
  16 05    0:     NULL
            :     }
  18 03  141:   BIT STRING 0 unused bits, encapsulates {
  22 30  137:       SEQUENCE {
  25 02  129:         INTEGER
            :           00 EB 11 E7 B4 46 2E 09 BB 3F 90 7E 25 98 BA 2F
            :           C4 F5 41 92 5D AB BF D8 FF 0B 8E 74 C3 F1 5E 14
            :           9E 7F B6 14 06 55 18 4D E4 2F 6D DB CD EA 14 2D
            :           8B F8 3D E9 5E 07 78 1F 98 98 83 24 E2 94 DC DB
            :           39 2F 82 89 01 45 07 8C 5C 03 79 BB 74 34 FF AC
            :           04 AD 15 29 E4 C0 4C BD 98 AF F4 B7 6D 3F F1 87
            :           2F B5 C6 D8 F8 46 47 55 ED F5 71 4E 7E 7A 2D BE
            :           2E 75 49 F0 BB 12 B8 57 96 F9 3D D3 8A 8F FF 97
            :           73
 157 02    3:         INTEGER 65537
            :         }
            :       }
            :   }

The OBJECT IDENTIFIER indicates that the following BIT STRING contains the encoding of an RSAPublicKey. The INTEGERs are the modulus and the public exponent.

You can decode the base64 with Convert.FromBase64String, but I don't think .NET has built-in functionality for parsing PublicKeyInfos, so you need to use a 3rd party tool like BouncyCastle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文