Convert Java.Security.KeyPair to .NET RSACryptoServiceProvider

后端 未结 2 784
深忆病人
深忆病人 2021-01-16 02:12

How can I encode a Java-produced RSA private (and public) key such that it can be decoded in .NET for use within RSACryptoServiceProvider?

I have tried

2条回答
  •  野的像风
    2021-01-16 03:05

    I found the answer in the PvkConvert.java file, which I've rewritten (in the relevant parts) as C# for use in Xamarin.Android apps as PvkConvert.cs.

    I learned that RSACryptoServiceProvider's native file format (when you use ExportCspBlob) is called PRIVATEKEYBLOB or PUBLICKEYBLOB (depending on whether the private key is included). Encoding a Java IPrivateKey as a PRIVATEKEYBLOB requires a few fields that evidently are only available on an originally generated IPrivateKey instance (one deserialized from storage does not cast to the necessary IRSAPrivateCrtKey interface.)

提交回复
热议问题