c# - How to generate CSR like it does IIS -
I am working on integration with the Symantap API and using that code to create a CSR
Private string GenerateCsr (string domain, string organization, string organization unit, string city, string state, string country) {Create all objects that objPkcs10 = new CX509CertificateRequestPkcs10 () will be required; Var objPrivateKey = New CX509PrivateKey (); Var objCSP = new CSP notification (); Var objCSPs = new CCSPInformations (); Var objDN = new CX500DistinguishedName (); Var objEnroll = New CX50 9Enrollment (); Var objObjectIds = new CObjectIds (); Var objObjectId = new CObjectId (); Var objExtensionKeyUsage = New CX509ExtensionKeyUsage (); Variable var var String strokequest; Try // // Start the CSP object using the desired Cryptoghaike Service Provider (CSP) objCSP.InitializeFromName ("Microsoft RSA Schannel Cryptographic Provider"); // Add this CSP object to the CSP archive object objCSPs.Add (objCSP); // Provide a private key object to key container name, key length and key device / / bajPrivateKey.ContainerName = "AlejaCMa"; ObjPrivateKey.Length = 2048; ObjPrivateKey.KeySpec = X509KeySpec.XCN_AT_SIGNATURE; ObjPrivateKey.KeyUsage = X509PrivateKeyUsageFlags.XCN_NCRYPT_ALLOW_ALL_USAGES; ObjPrivateKey.MachineContext = false; // Provide private key object objPrivateKey.CspInformations = objCSPs to CSP collection object (in this case only containing 1 CSP object) //; // create real key pair objPrivateKey.Create (); // PKCS # 10 certificate request based on private key. Use the reference // Use context, tell that it is not a user certificate request nor does not // provide a template name objPkcs10. InitializeFromPrivateKey (X509CertificateEnrollmentContext.ContextUser, objPrivateKey, ""); // Key Usage extension objExtensionKeyUsage.InitializeEncode (X509KeyUsageFlags.XCN_CERT_DIGITAL_SIGNATURE_KEY_USAGE | X509KeyUsageFlags.XCN_CERT_NON_REPUDIATION_KEY_USAGE | X509KeyUsageFlags.XCN_CERT_KEY_ENCIPHERMENT_KEY_USAGE | X509KeyUsageFlags.XCN_CERT_DATA_ENCIPHERMENT_KEY_USAGE); ObjPkcs10.X509Extensions.Add ((CX509Extension) objExtensionKeyUsage); // Enhanced Key Usage extension objObjectId.InitializeFromValue ("1.3.6.1.5.5.7.3.2"); // objObjectIds.Add (objObjectId) for the use of OID client authentication; ObjX509ExtensionEnhancedKeyUsage.InitializeEncode (objObjectIds); ObjPkcs10.X509Extensions.Add ((CX509Extension) objX509ExtensionEnhancedKeyUsage); // Name specific name object using objDN.Encode (string.Format ("CN = {0}, O = {1}, OU = {2}, L = {3}, S = {4}, Encode, c = {5} ", domain, organization, organization unit, city, state, country), X500NameFlags.XCN_CERT_NAME_STR_NONE); // objPkcs10.Subject = objDN Assing the topic name using the specific name object that started above; // Create nomination request objEnroll.InitializeFromRequest (objPkcs10); StrRequest = objEnroll.CreateRequest (encoding type.XCN_CRYPT_STRING_BASE64); Return Stratquest; } Hold (exception before) {new exception throw ("can not generate CSR"); }} Symantec then returns base 64 encoded certificates, but I can not upload it to IIS. If I manually generate CIR manually on Symantec on IIS, then I am able to upload the returned certificate. So, my question arises on how the CSR arises on IIS.
This can not be done the way you want it since CSR and private key is generated On a server, signed certificate back by CA, you will need a private key generated when you create a CSR. But you are generating a private key on a separate server and uploading a signed certificate given by Symantec on IIS and IIS does not have a private key.
If this is to be done then you will be given the parameter directly to the SimTech API and then they will provide you a PFX file that will be password protected and you can upload a PFX file to the IIS server.
I hope that I answered the question to you.
Comments
Post a Comment