locked
SSL over SOAP with xxxxxx.jks file RRS feed

  • Question

  • User-665585339 posted

    Hi I currently implement SSL Call to SOAP, i believe the client are java, as i have below files on certificate:-

    xxx.crt

    xxx.jks

    In SoapUI, i able successfully import the keystore file (xxx.jks), by enter the password, it go through.

    But in C# NET code, when i load certificate (The xxx.jks file), throw below error:

    ExceptionMessage: System.Security.Cryptography.CryptographicException: Cannot find the requested object.

       at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
       at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
       at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)

    Wednesday, February 26, 2014 11:04 PM

Answers

  • User-417640953 posted

    Hi johnlim35,

    Thanks for your post.

    For importing X509Certificates key certificate you can try below code.

    X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    certificateStore.Open(OpenFlags.ReadOnly);
    var exportCertificates = certificateStore.Certificates.Find(X509FindType.FindByThumbprint, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", false);
    certificateStore.Close();
    
    // Get Base64 string of the public key
    byte[] arr = exportCertificates[0].RawData;
    string b64ExportCertificate = Convert.ToBase64String(arr);
    
    // Import the certificate
    X509Certificate2 importCertificate = new X509Certificate2(Convert.FromBase64String(b64ExportCertificate));

    http://msdn.microsoft.com/en-us/library/ms731899(v=vs.110).aspx

    If you still cannot solve it, please feel free to back and share your code with us. Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 2, 2014 7:04 AM