EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Export certificate from

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#30509
Posted: 08/27/2014 11:05:26
by Rene Schoenfelder (Standard support level)
Joined: 08/27/2014
Posts: 3

Hi,

I use an USB token for signatures: a TElWinCertStorage.

Now I would like export the certificate to a .cer file. How can I do that in C#?

(The method SaveToFile has no option .cer defined: https://www.eldos.com/documentation/sbb/documentation/ref_cl_certificate_mtd_savetofile.html)

Thank you,

René
#30510
Posted: 08/27/2014 11:07:59
by Eugene Mayevski (EldoS Corp.)

Find the certificate in TElWinCertStorage in some way (either by enumeration or by using Lookup object), then save the certificate (eg. "storage.get_Certiicates(1)") to .cer file using a call to TElX509Certificate.SaveToStream(InstanceOfFileStreamClass) method.


Sincerely yours
Eugene Mayevski
#30511
Posted: 08/27/2014 11:13:58
by Rene Schoenfelder (Standard support level)
Joined: 08/27/2014
Posts: 3

Thank you
#30570
Posted: 09/01/2014 15:26:30
by Rene Schoenfelder (Standard support level)
Joined: 08/27/2014
Posts: 3

The method SaveToStream returns an empty String:

TElX509Certificate Cert = getCertificate();
Cert.SaveToStream(new FileStream(path, FileMode.Create));

Also, it doesn't aks for my token password.
#30571
Posted: 09/01/2014 15:33:53
by Eugene Mayevski (EldoS Corp.)

First please inspect (with debugger) that Cert contains a certificate after a call to getCertificate(). "Contains" means an object with CertificateSize property greater than 0. This means that the certificate has been retrieved.

Now, in your code the stream is not closed. This means that the file will have zero length until the application exit (or for some other quite long time). Try to rewrite it to

Code
Stream stream = new FileStream(path, FileMode.Create);
try
{
  Cert.SaveToStream(stream);
}
finally
{
  stream.Close();
}


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 544 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!