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