EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Certificate to Base64

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
Posted: 11/06/2009 11:02:14
by Eduardo Tijerina (Basic support level)
Joined: 11/06/2009
Posts: 6


FCert: TElX509Certificate;

I have already loaded the certificate for
some task.

Now, is there a simple way to get the text
representation of the certificate in base64

Posted: 11/06/2009 11:36:01
by Ken Ivanov (Team)

Please use TElX509Certificate.SaveToStreamPEM method to have the certificate in PEM (base64) form.
Posted: 11/09/2009 12:44:20
by Eduardo Tijerina (Basic support level)
Joined: 11/06/2009
Posts: 6

Works for me, but is there an option to get rid of begin and end marks.
Posted: 11/09/2009 13:39:16
by Ken Ivanov (Team)

If you need to omit headers, please use SBUtils.Base64Encode() function. It is internal and thus not documented, but it works. The declaration looks like the following:

function Base64Encode(InBuffer : pointer; InSize : integer; OutBuffer : pointer;
var OutSize : integer; WrapLines : boolean = true) : boolean;
Posted: 10/15/2013 10:12:59
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Hi! I'm trying to execute the SaveToPEM function in my code, however, I displayed a message to locate the file SBX509.pas. "Source file not found".

On the other hand, there is documentation Base64Encode function () and how to use it?
Posted: 10/15/2013 12:15:27
by Eugene Mayevski (Team)

What's wrong with SaveToPEM function? If it's looking for the source code, it probably wants to show some place where exception happens. Which in turn means that you've passed wrong parameters (which cause exception).

Sincerely yours
Eugene Mayevski
Posted: 10/15/2013 12:38:55
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Thanks for your response.

Most likely it is as you say, an error in the parameter passing. The "SaveToStreamPEM" calls for Stream and PhassPhrase, the latter can be any? or has to be the password of private key file (. key)?

This is my code:

procedure TfrmMain.btnCer2Base64Click(Sender: TObject);
F : TFileStream;
Cert : TElX509Certificate;
St : TStream;
St := TStream.Create;
Cert := TElX509Certificate.Create(nil);
F := TFileStream.Create('MyCertifcate.cer', fmOpenRead);

Posted: 10/15/2013 12:40:29
by Eugene Mayevski (Team)

TStream is an abstract class and you can't use it. In your code you need to use TMemoryStream. Remember to free it after use to avoid memory leak.

On a side note please use CODE button to mark the beginning and the end of the code block in your messages.

Sincerely yours
Eugene Mayevski
Posted: 10/15/2013 12:53:35
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Thanks Eugene.

I already did it. I have no error message now. I changed the TStream for TMemoryStream but still nothing happens, I can not see the contents of my certificate in Base64.
Posted: 10/15/2013 12:59:25
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9


I'm still investigating. I could save the stream to a TXT file and there if I can see the content, then something is going on with my way of wanting to see the contents of that variable ....



I already could read the contents of TMemoryStream and pass it to a String
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.



Topic viewed 2518 times

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


Back to top

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

Got it!