Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 09, 2012 10:26 AM by sailajatummala
0 Points
9 Posts
May 09, 2012 09:29 AM|LINK
How to create a .p12 certificate files in c#.net?
Star
7625 Points
1454 Posts
May 09, 2012 09:34 AM|LINK
have you gone through this?
http://stackoverflow.com/questions/2039364/how-do-i-create-a-pkcs12-p12-file-in-c
May 09, 2012 10:01 AM|LINK
RsaPrivateCrtKeyParameters KeyParams = (RsaPrivateCrtKeyParameters)this.KeyPair.Private; --- in this line only showing error
All-Star
95493 Points
14106 Posts
May 09, 2012 10:23 AM|LINK
use Bouncy Castle - BouncyCastle
Thanks,
May 09, 2012 10:26 AM|LINK
AsymmetricCipherKeyPair keyPair = createASymRandomCipher(); RsaPrivateCrtKeyParameters KeyParams = (RsaPrivateCrtKeyParameters)keyPair.Private; RSAParameters rsaParameters = new RSAParameters();
rsaParameters.Modulus = KeyParams.Modulus.ToByteArrayUnsigned(); rsaParameters.P = KeyParams.P.ToByteArrayUnsigned(); rsaParameters.Q = KeyParams.Q.ToByteArrayUnsigned(); rsaParameters.DP = KeyParams.DP.ToByteArrayUnsigned(); rsaParameters.DQ = KeyParams.DQ.ToByteArrayUnsigned(); rsaParameters.InverseQ = KeyParams.QInv.ToByteArrayUnsigned(); rsaParameters.D = KeyParams.Exponent.ToByteArrayUnsigned(); rsaParameters.Exponent = KeyParams.PublicExponent.ToByteArrayUnsigned();
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(); rsaKey.ImportParameters(rsaParameters);
X509Certificate2 cert = new X509Certificate2();
cert.PrivateKey = rsaKey; ----- here it is giving a "m_safecertcontext is an invalid handle" an exception
private static AsymmetricCipherKeyPair createASymRandomCipher() { RsaKeyPairGenerator r = new RsaKeyPairGenerator(); r.Init(new KeyGenerationParameters(new SecureRandom(),1024)); AsymmetricCipherKeyPair keys = r.GenerateKeyPair(); return keys; }
sailajatumma...
0 Points
9 Posts
Create .p12 certificate files
May 09, 2012 09:29 AM|LINK
How to create a .p12 certificate files in c#.net?
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Create .p12 certificate files
May 09, 2012 09:34 AM|LINK
have you gone through this?
http://stackoverflow.com/questions/2039364/how-do-i-create-a-pkcs12-p12-file-in-c
MCP
sailajatumma...
0 Points
9 Posts
Re: Create .p12 certificate files
May 09, 2012 10:01 AM|LINK
ramiramilu
All-Star
95493 Points
14106 Posts
Re: Create .p12 certificate files
May 09, 2012 10:23 AM|LINK
use Bouncy Castle - BouncyCastle
Thanks,
JumpStart
sailajatumma...
0 Points
9 Posts
Re: Create .p12 certificate files
May 09, 2012 10:26 AM|LINK
AsymmetricCipherKeyPair keyPair = createASymRandomCipher();
RsaPrivateCrtKeyParameters KeyParams = (RsaPrivateCrtKeyParameters)keyPair.Private;
RSAParameters rsaParameters = new RSAParameters();
rsaParameters.Modulus = KeyParams.Modulus.ToByteArrayUnsigned();
rsaParameters.P = KeyParams.P.ToByteArrayUnsigned();
rsaParameters.Q = KeyParams.Q.ToByteArrayUnsigned();
rsaParameters.DP = KeyParams.DP.ToByteArrayUnsigned();
rsaParameters.DQ = KeyParams.DQ.ToByteArrayUnsigned();
rsaParameters.InverseQ = KeyParams.QInv.ToByteArrayUnsigned();
rsaParameters.D = KeyParams.Exponent.ToByteArrayUnsigned();
rsaParameters.Exponent = KeyParams.PublicExponent.ToByteArrayUnsigned();
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();
rsaKey.ImportParameters(rsaParameters);
X509Certificate2 cert = new X509Certificate2();
cert.PrivateKey = rsaKey; ----- here it is giving a "m_safecertcontext is an invalid handle" an exception
private static AsymmetricCipherKeyPair createASymRandomCipher()
</div>{
RsaKeyPairGenerator r = new RsaKeyPairGenerator();
r.Init(new KeyGenerationParameters(new SecureRandom(),1024));
AsymmetricCipherKeyPair keys = r.GenerateKeyPair();
return keys;
}