我有格式的RSA私钥PEM,是否有直接的方式从.NET读取并实例化RSACryptoServiceProvider解密用相应的公钥加密的数据?
此代码与反垃圾邮件工作中使用的DKIM签名验证有关.
我有一个byte[]来自s1024._domainkey.yahoo.comASN.1编码,但我不知道是否仅包含足够的信息来实现公钥.
基于这个类,看来我可以转换的ASN.1钥匙插入X509证书公钥,但我需要提供一个OID和一些ASN.1编码参数.
在此示例中,我有ASN1密钥为的元数据:
/*
* 1.2.840.113549.1
*
MD2 md2WithRSAEncryption ::= {pkcs-1 2}
MD5 md5WithRSAEncryption ::= {pkcs-1 4}
SHA-1 sha1WithRSAEncryption ::= {pkcs-1 5}
SHA-256 sha256WithRSAEncryption ::= {pkcs-1 11}
SHA-384 sha384WithRSAEncryption ::= {pkcs-1 12}
SHA-512 sha512WithRSAEncryption ::= {pkcs-1 13}
*/
Run Code Online (Sandbox Code Playgroud)
代码示例
string pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB";
byte[] pubkeyByteArray = Convert.FromBase64String(pubkey);
AsnEncodedData aData = new AsnEncodedData(pubkeyByteArray);
// OID must not be null, but it is here. What is it? …Run Code Online (Sandbox Code Playgroud)