对`PublicKeyFactory.CreateKey()`的反操作 [英] Inverse operation to `PublicKeyFactory.CreateKey()`

查看:710
本文介绍了对`PublicKeyFactory.CreateKey()`的反操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用带有C#的Bouncycastle,什么是相反的操作?

Using Bouncycastle with C#, what is the inverse operation to:

byte[] publicKey;
AsymmetricKeyParameter asymmetricKeyParameter = PublicKeyFactory.CreateKey(publicKey);
RsaKeyParameters rsaKeyParameters = (RsaKeyParameters)asymmetricKeyParameter;

即我有一个包含公用密钥的 RsaKeyParameters 对象,并希望将其转换为字节数组,以便可以将其反馈给 PublicKeyFactory .CreateKey()

I.e. I have a RsaKeyParameters object containing a public key and want to convert it to a byte array in such a way that I could feed it back in to PublicKeyFactory.CreateKey()

推荐答案

公钥的逆运算应为:

byte[] publicKey = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(rsaKeyParameters).GetDerEncoded();

该工厂类位于Org.BouncyCastle.X509命名空间中。

That factory class is in the Org.BouncyCastle.X509 namespace.

对于私钥,相应的工厂类为Org.BouncyCastle.Security.PrivateKeyFactory和Org.BouncyCastle.Pkcs.PrivateKeyInfoFactory / EncryptedPrivateKeyInfoFactory。

For private keys, the corresponding factory classes are Org.BouncyCastle.Security.PrivateKeyFactory and Org.BouncyCastle.Pkcs.PrivateKeyInfoFactory/EncryptedPrivateKeyInfoFactory.

这篇关于对`PublicKeyFactory.CreateKey()`的反操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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