Click here to Skip to main content
15,907,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to use the below code, please let me know the dll reference to be added for this code to work.

<pre lang="c#">
var privateKey = new PrivateKey(PrivateKey.KeySpecification.AtKeyExchange, 2048, false, true);

            var caCertificateRequest = new CaCertificateRequest(); 

            string csr = caCertificateRequest.GenerateRequest("cn=test", privateKey);

            //Load signing certificate from MDM_pfx.pfx, this is generated using signingCertificatePrivate.pem and SigningCert.pem.pem using openssl
           
            var cert = new X509Certificate2(MY_MDM_PFX, PASSWORD, X509KeyStorageFlags.Exportable);

            //RSA provider to generate SHA1WithRSA

            var crypt = (RSACryptoServiceProvider)cert.PrivateKey;
            var sha1 = new SHA1CryptoServiceProvider();
            byte[] data = Convert.FromBase64String(csr);
            byte[] hash = sha1.ComputeHash(data);
            //Sign the hash 
            byte[] signedHash = crypt.SignHash(hash, CryptoConfig.MapNameToOID("SHA1")); 
            var signedHashBytesBase64 = Convert.ToBase64String(signedHash);
Posted
Comments
Richard MacCutchan 27-Nov-14 7:41am    
You first need to explain what is not working.
Vignan Galla 28-Nov-14 0:23am    
Hi Richard,
I am not able to build the application, since it throws an error near "PrivateKey" and "CaCertificateRequest".
I am missing the namespace to be included for these.

1 solution

Just with a quick glance I don't see any 3rd party code. This is all .Net code. Which is nice because if you are getting an error about missing a reference all you do is hover over where it shows the issue and you get a smart tooltip that will give you the option to choose "using ...."

However, it may be as simple as missing the System.Security in references.
 
Share this answer
 
Comments
Vignan Galla 28-Nov-14 0:17am    
Hi RyanDev, thank you for your reply.
But I have already tried the work around as explained by you.
And also I have used the below references.

using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;

However it still shows an error near "PrivateKey" and "CaCertificateRequest".
And the smart tooltip does not show any option for choosing the using...

I strongly believe that I am missing a dll reference or a COM object.
ZurdoDev 28-Nov-14 9:30am    
You'll need to check with wherever you got the code from. It could be a custom class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900