EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Certificate to Base64

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#11578
Posted: 11/06/2009 11:02:14
by Eduardo Tijerina (Basic support level)
Joined: 11/06/2009
Posts: 6

Hi.-

using
FCert: TElX509Certificate;
FCert.LoadFromStream(Stream);

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
encoding.

TIA
#11579
Posted: 11/06/2009 11:36:01
by Ken Ivanov (EldoS Corp.)

Please use TElX509Certificate.SaveToStreamPEM method to have the certificate in PEM (base64) form.
#11616
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.
#11618
Posted: 11/09/2009 13:39:16
by Ken Ivanov (EldoS Corp.)

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;
#26822
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?
#26826
Posted: 10/15/2013 12:15:27
by Eugene Mayevski (EldoS Corp.)

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
#26827
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);
var
F : TFileStream;
Cert : TElX509Certificate;
St : TStream;
begin
St := TStream.Create;
Cert := TElX509Certificate.Create(nil);
try
F := TFileStream.Create('MyCertifcate.cer', fmOpenRead);
try
Cert.LoadFromStream(F);
Cert.SaveToStreamPEM(St,'mypassword');
Memo1.Lines.LoadFromStream(St);
finally
FreeAndNil(F);
end;
finally
FreeAndNil(Cert);
end;
end;

Thanks!
#26828
Posted: 10/15/2013 12:40:29
by Eugene Mayevski (EldoS Corp.)

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
#26829
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.
#26830
Posted: 10/15/2013 12:59:25
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Sorry!

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 ....

thanks

---------------------------------------------------------------------------------
Thanks,

I already could read the contents of TMemoryStream and pass it to a String
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

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