阅读ASN.1 DER编码RSA公共密钥 [英] Reading a ASN.1 DER-encoded RSA Public key

查看:902
本文介绍了阅读ASN.1 DER编码RSA公共密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,以更好地了解DKIM的。该规范说,我检索ASN.1 DER编码公众从域TXT记录键。我可以看到关于s1024._domainkey.yahoo.com=+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz QfiWYui / E9UGSXau / 2P8LjnTD8V4Unn + 2FAZVGE3kL23bzeoULYv4PeleB3gfm。

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".

如何使用此键。净?我见过从一个X509Certificate2或包含RSAParameters一个XML文件的密钥的例子

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.

修正:我复制/粘贴键上方从network-tools.com DNS工具,一定是把它剪短。 NSLOOKUP给我的全键:

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文字=
K = RSA;吨= Y ; p = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz + QfiWYui / E9UGSXau2P8LjnTD8V4Unn + 2FAZVGE3kL23bzeoULYv4PeleB3gfm
JiDJOKU3Ns5L4KJAUUHjFwDebt0NP + sBK0VKeTATL2Yr / S3bTxhy + 1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj + XcwIDAQAB; N = A 1024位的密钥;

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

所以abelenky是正确的轨道上BASE64 ..

So abelenky was on the right track with BASE64..

推荐答案

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

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

下面是翻译:

   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
            :         }
            :       }
            :   }

对象标识符表示后面的BIT字符串包含一个RSAPublicKey的编码。这个整数是模数和公开指数。

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

您可以用的 Convert.FromBase64String ,但我不认为.NET已经内置功能解析PublicKeyInfos,所以你需要使用第三方工具,如BouncyCastle的。

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.

这篇关于阅读ASN.1 DER编码RSA公共密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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