Inverse operation to `PublicKeyFactory.CreateKey()`

試著忘記壹切 提交于 2020-01-06 11:45:50

问题


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

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

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()


回答1:


The inverse operation for public keys should be:

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

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

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



来源:https://stackoverflow.com/questions/17159147/inverse-operation-to-publickeyfactory-createkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!