BouncyCastle RSAPrivateKey to .NET RSAPrivateKey?

FYI, I've added this functionality to the Org.BouncyCastle.Security. DotNetUtilities class; it will be in release 1.6, due soon.

I found it! Or atleast part of it :) As for the PrivateKey. ExportToParameters(true) Still doens't work but this has something todo with the fact that the key was 2048 bit.

Because when I changed it to 1024bit it did work. So if anyone ever finds out why keep me posted. So here we go again.

//BouncyCastle's Key objects RsaPrivateCrtKeyParameters rpckp = ((RsaPrivateCrtKeyParameters)ackp. Private); //. NET RSA Key objects System.Security.Cryptography.

RSACryptoServiceProvider rcsp = new System.Security.Cryptography. RSACryptoServiceProvider(); System.Security.Cryptography. RSAParameters parms = new System.Security.Cryptography.RSAParameters(); //So the thing changed is offcourse the ToByteArrayUnsigned() instead of //ToByteArray() parms.

Modulus = rpckp.Modulus. ToByteArrayUnsigned(); parms. P = rpckp.P.

ToByteArrayUnsigned(); parms. Q = rpckp.Q. ToByteArrayUnsigned(); parms.

DP = rpckp.DP. ToByteArrayUnsigned(); parms. DQ = rpckp.DQ.

ToByteArrayUnsigned(); parms. InverseQ = rpckp.QInv. ToByteArrayUnsigned(); parms.

D = rpckp.Exponent. ToByteArrayUnsigned(); parms. Exponent = rpckp.PublicExponent.

ToByteArrayUnsigned(); //So now this now appears to work. Rcsp. ImportParameters(parms); So now I can add the complete Certificate to my store :).

1 I was looking for this particular solution for the last 1 week. Your solution did work for me. Thank you for sharing :) – AbrahamJP May 30 at 15:05.

I think I found the solution to this problem. It has nothing to do with the key per, but rather with the X509Certificate2 object which must be created with the X509KeyStorageFlags. Exportable flag.In this case your X509Certificate2 was created by this method: System.Security.Cryptography.

X509Certificates. X509Certificate2 netcert = DotNetUtilities. ToX509Certificate(cert); So make sure you pass the exportable flag in the constructor of the X509Certificate2 in that method.

I my situation I needed to sign some data with a private key located in a PFX file so I had to write this: X509KeyStorageFlags flags = X509KeyStorageFlags. Exportable; X509Certificate2 cert = new X509Certificate2("my. Pfx", "somepass", flags); Now I can do RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.

PrivateKey; RSAParameters rsaParam = rsa. ExportParameters(true); HTH, Stefan.

Very thanks! I've been struggled this problem. – kuy Feb 18 at 17:31.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions