c#-获取DER编码的公钥

使用BounceCastle,我可以运行以下代码.
它生成密钥对并返回ASN.1 DER编码的格式.

//Generate new key
var generator = new RsaKeyPairGenerator ();
generator.Init (new KeyGenerationParameters (new SecureRandom (), 1024));
var keyPair = generator.GenerateKeyPair ();

//Save private key for later use
keyParameters = (RsaKeyParameters)keyPair.Private;

//Export ASN.1 DER-encoded
SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public);
return info.GetEncoded ();

它已经过测试,可与第三方软件一起使用.

我的问题是:如何使上述编码相反.
具有已编码的公共密钥,如何将公共密钥转换为RsaKeyParameters.

我想我要做类似的事情.

SubjectPublicKeyInfo s = new SubjectPublicKeyInfo(????, publicKeyBytes);
RsaKeyParameters key = (RsaKeyParameters)PublicKeyFactory.CreateKey(s);

因此,如果这很接近,我需要知道要放什么????,它需要一个类型为AlgorithmIdentifier的对象.

最佳答案
多亏了this answer,我得到了以下代码:

        AsymmetricKeyParameter asymmetricKeyParameter = PublicKeyFactory.CreateKey(req.PublicKey);
        RsaKeyParameters key = (RsaKeyParameters) asymmetricKeyParameter;

转载注明原文:c#-获取DER编码的公钥 - 代码日志