EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Converting a cert and key into a TElX509Certificate object

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#28566
Posted: 02/25/2014 16:04:56
by T  (Basic support level)
Joined: 02/25/2014
Posts: 4

I have a cert and key in pem format, that I am trying to combine into a PFX file, that I can subsequently load into a TElX509Certificate object.

Essentially, the steps I am doing are as follows:
1) Generating a csr, using TElCertificateRequest.
2) Save key from this csr, using SaveKeyToStreamPEM.
3) Generate cert from csr, which gives PEM formatted cert.
4) Load key and cert into TElX509CertificateEx object using LoadFromBufferPEM and LoadKeyFromBufferPEM.
5) Attempt to save cert and key as PFX by calling SaveToStreamPFX.

The first four steps work correctly, but when I call SaveToStreamPFX, I get the following exception:

A first chance exception of type 'System.NullReferenceException' occurred in SecureBlackbox.DLL
An exception of type 'System.NullReferenceException' occurred in SecureBlackbox.DLL and wasn't handled before a managed/native boundary

Has anyone come across that before, or knows if I am doing the correct steps or not? I am trying this out on Windows Phone 8.

Thanks in advance for any help,
Regards,
#28568
Posted: 02/25/2014 17:07:26
by Ken Ivanov (EldoS Corp.)

Hello,

Thank you for contacting us.

The steps you described are correct and should work. Could you show us the call stack of the exception please?

Ken
#28581
Posted: 02/26/2014 10:58:53
by T  (Basic support level)
Joined: 02/25/2014
Posts: 4

Hi Ken,
Thanks for your response.

This is the info that we catch in our exception handler (the message and stacktrace):

Exception caught: Object reference not set to an instance of an object.

Stack trace: at SBX509.TElX509Certificate.SaveToBufferPFX(Byte[]& Buffer, Int32& Size, String Password, Int32 KeyEncryptionAlgorithm, Int32 CertEncryptionAlgorithm)
at SBX509.TElX509Certificate.SaveToStreamPFX(Stream Stream, String Password, Int32 KeyEncryptionAlgorithm, Int32 CertEncryptionAlgorithm)
at SBX509.TElX509Certificate.SaveToStreamPFX(Stream Stream, String Password)
at MyCrypto.GenerateP12(String password, String cKey, String cert)
#28586
Posted: 02/26/2014 14:34:06
by Vsevolod Ievgiienko (EldoS Corp.)

Please post here a code that we can use to reproduce the problem and clarify what SecureBlackbox version is used.
#28590
Posted: 02/26/2014 17:50:17
by T  (Basic support level)
Joined: 02/25/2014
Posts: 4

I am using SecureBlackBox version: 11.0.245

Code
try
{
    byte[] arr = null;
    using (TElX509CertificateEx x509Cert = new TElX509CertificateEx())
    {
        int res = x509Cert.LoadKeyFromBufferPEM(SBStrUtils.__Global.StrToUTF8(cert), "");
        res = x509Cert.LoadKeyFromBufferPEM(SBStrUtils.__Global.StrToUTF8(cKey), password);

        using (System.IO.MemoryStream pfxStream = new System.IO.MemoryStream())
        {
            x509Cert.SaveToStreamPFX(pfxStream, password);
            arr = pfxStream.ToArray();
        }
    }
    return arr;
}
catch(Exception e)
{
    Debug.WriteLine("Exception: {0}", e.Message);
    Debug.WriteLine("Stack trace: {0}", e.StackTrace);
    return null;
}
#28593
Posted: 02/27/2014 01:01:23
by Vsevolod Ievgiienko (EldoS Corp.)

Your code is correct.

Please check the value of 'err' variable. It should contain '0' if loading procedure was successful and error code otherwise.

BTW, please use CODE tag for code.
#28757
Posted: 03/11/2014 13:38:36
by T  (Basic support level)
Joined: 02/25/2014
Posts: 4

Thanks for the response, Vsevolod, and sorry I didn't respond earlier.
Turns out the issue was of my own doing; I think I was a bit too eager with the "Tab" button when I was adding the cert import functionality, and tabbed when I was on LoadKeyFromBufferPEM, when it should have been "LoadFromBufferPEM".
When I used the correct API, everything worked as expected.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 1557 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!