在Net中。如何将这两个数组转换为“不带PEM头的PKCS1公钥”?
谢谢。
发布于 2010-12-27 17:43:26
如果您只需要对RSA公钥进行编码,您可以编写自己的包装器,这将需要5行代码。RSA公钥应表示为以下ASN.1结构:
RSAPublicKey ::=序列{模数整数,-- n publicExponent整数-- e}
但是,这需要您学习一些ASN.1基础知识。此外,您应该确保您只需要以这种格式保存,应用程序也可能需要添加algorithmIdentifier。
发布于 2010-12-27 08:21:47
必须有一种更简单的方法,但一种方法是使用Bouncycastle C# library及其几个类,如下例所示:
using System.Security.Cryptography;
using Org.BouncyCastle.Asn1;
public static byte[] DEREncode(RSACryptoServiceProvider rsa)
{
RSAParameters rsaParams = rsa.ExportParameters(false);
DerInteger n = new DerInteger(rsaParams.Modulus);
DerInteger e = new DerInteger(rsaParams.Exponent);
DerSequence seq = new DerSequence(new Asn1Encodable[] {n, e});
return seq.GetEncoded();
}https://stackoverflow.com/questions/4535563
复制相似问题