I am trying to read the RSA private key in .Net using BouncyCastle to verify the data I previously encrypted. The encrypted data works fine using the public key and Bouncy Castle, and I also used the same private key as below (which is DER format) to successfully decrypt my data in a PHP application, but I don't know why I cannot create .Net private key to do the same:
byte[] privatekey = File.ReadAllBytes(@"C:\Users\Luke\privkey.der");
var rsaKeyParameters = (RsaKeyParameters)PrivateKeyFactory.CreateKey(privatekey);
The second line throws an exception:
"unknown object in factory: DerInteger \ r \ nParameter: obj"
I also tried using a stream instead of a byte array and the same error. The key pair was created using OpenSSL, and as already mentioned, decryption works in PHP using openssl_private_decrypt () and the same key as in the .Net code. I also tried the PEM format of the same key, and that didn't work either (but I don't think BC supports PEM directly)
Has anyone done this before? Thanks
Lukos source
share