EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Invalid Base64 Encoding

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#9900
Posted: 05/04/2009 19:20:42
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Hi all!

I am evaluating your product (SecureBlackbox for Delphi 4-7 - Version 7.0.156). I need to sign a string using the RSA algorithm and give results in Base64 encoding.

I have a file containing a public key (extension. PFX).

The procedure to do it is:
I use the source code that is in the directory
..\Samples\Deplhi\PKIBlackBox\Primitives\SignDetached

- Input file: OriginalString.TXT
- Output file: Encrypted.TXT
- Encryption algorithm: RSA
- Input encoding: Binary
- Output encoding: Base64
- P key container file: MyKey.PFX
- Password: MyPassw
- Key container type: X.509 Certificate

So here it seems that there is no problem. However, when I try to verify this file that I generate, with the code is in
..\Samples\Deplhi\PKIBlackBox\Primitives\VerifyDetached an error occurred ('Invalid Base64 Encoding').

The parameters used in this code are:
- Input filename: OriginalString.TXT
- Signature filename: Encrypted.TXT
- Encryption algorithm: RSA
- Input Encoding: Base64
- P key container file: MyKey.PFX
- Password: MyPassw
- Key container type: X.509 Certificate


What am I doing wrong? Where is it the error?
Somebody help me please!!

Thank you
#9901
Posted: 05/04/2009 23:47:05
by Ken Ivanov (EldoS Corp.)

Thank you for your interest in our products.

TElRSAPublicKeyCrypto with InputEncoding set to Base64 expects *both* input data and signature to be encoded in Base64. As your data is not encoded in Base64, an appropriate exception is thrown.
#10030
Posted: 05/15/2009 20:32:24
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Thank you very much, the problem was solved. I encoded both files in Base64 and it works!

Now I have a new problem: I have a certificate file with the extension. .CER, how can I do to covert it into a. PFX extension file?
#10032
Posted: 05/16/2009 02:30:24
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

You should load it, using .LoadFromBuffer (or .LoadFromStream) method, and save, using .SaveToBufferPFX/.SaveToStreamPFX.
#10054
Posted: 05/18/2009 18:07:32
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Sorry, I'm not very familiar with the component. There is some source code example that involves these features?
#10055
Posted: 05/18/2009 20:24:00
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

Within the sample programs PKIBlackBox component, I'm trying "CertDemo_BDS2005" made to Delphi. I have my file. And make their own. Key, as well as the password. When I try to load the certificate it asks me if I want to load the private key, however I mark an error "Invalid Secret Key". Include files that I'm working "aaa010101aaa_CSD_01.cer, aaa010101aaa_CSD_01.key. Password: a0123456789.

Sorry, try to send them, but the message exceeds the limit. However, there is an application 'Online' (http://dictamex.edomex.gob.mx/portal/web/public/70) I take these same files, the password and I generated the .PFX with no problem.

Any idea?
#10056
Posted: 05/19/2009 01:29:16
by Eugene Mayevski (EldoS Corp.)

Put the files to ZIP archive and post it to the HelpDesk. But from your message it look like your .key file is not in the format that you choose. If it's password-protected, then it's either in PEM format, or in PKCS#8...


Sincerely yours
Eugene Mayevski
#10063
Posted: 05/19/2009 10:16:56
by Cesar Ruiz (Basic support level)
Joined: 04/30/2009
Posts: 9

I just put them in Helpdesk ... thank you

Sincerely yours
Cesar Ruiz
#12544
Posted: 02/22/2010 17:34:05
by Cesar Ruiz (Basic support level)
Joined: 02/22/2010
Posts: 1

Hello, greetings to all!

I need your help once again.

Almost a year ago I turned to you to help me to convert a file with .CER extension,into another one with .PFX extension.

Everything worked fine until today. Today, after doing the conversion,
I used the resulting file (PFX) to sign a string and generate a digital stamp.

There was not any problem until today, instead of getting results in the digital seal the result is a message that says: "Secret key not found".

The conversion of .CER file to a .PFX was successful (or at least I think).To build the .PFX is required a .CER file, a .KEY file too and a password.

If the file .KEY or password are not correct, the routine generates an error message and no conversion takes place, however if I could generate the PFX file without problem.

The question is why I get this error message ("Secret key not found") instead of the digital stamp?

Any idea?

Thank you very much for everything, and I hope I you can help me again!

------------------------------------------------------------------------------
This segment of code that generates the digital seal
------------------------------------------------------------------------------
function ObtenSelloDigital(stMyString,stPFXfile,password:string):string;
var myFile : TextFile;
InputFile : String;
OutputFile : String;
stSelloDigital : String;
stMD5 : String;
stB64 : String;
begin

if fileExists(stPFXfile) then begin
// Hash MD5
stMD5 := stMyString;
stMD5 := CalcHash2(stMyString,haMD5);
// Base64 encoding
stB64 := B64Encode(stMD5);
// Generate _InputFile B64 encoded
InputFile := ExtractFileDir(stPFXfile) + '\ORI_' + FechaHora() + '.TXT';
OutPutFile := ExtractFileDir(stPFXfile) + '\SGN_' + FechaHora() + '.TXT';
AssignFile(myFile,InputFile);
Rewrite(myFile);
Writeln(myFile,stB64);
CloseFile(myFile);
// Sign inputFile
result := DoSignDetached(InputFile, OutputFile, stPFXfile, password);
end else result := 'Imposible generar el Sello Digital: NO EXISTE EL ARCHIVO ['+stPFXfile+']';
end;
-----------------------------------------------------------------------------


-----------------------------------------------------------------------------
This segment of code that converts a CER into a PFX
-----------------------------------------------------------------------------
function ConvertCerToPFX(KEYfile, CERfile, PFXfile,password:string):boolean;
var
P8 : TElPKCS8PrivateKey;
R : integer;
F : TFileStream;
Cert : TElX509Certificate;
KM : BufferType;
begin
P8 := TElPKCS8PrivateKey.Create();
result := false;
try
F := TFileStream.Create(KEYfile, fmOpenRead);
try
R := P8.LoadFromStream(F, password);
Assert(R = 0);
finally
FreeAndNil(F);
end;

Cert := TElX509Certificate.Create(nil);
try
F := TFileStream.Create(CERfile, fmOpenRead);
try
Cert.LoadFromStream(F);
finally
FreeAndNil(F);
end;
KM := P8.KeyMaterial;
Cert.LoadKeyFromBuffer(@KM[1], Length(KM));

F := TFileStream.Create(PFXfile, fmCreate);
try
Cert.SaveToStreamPFX(F, password);
result := true;
finally
FreeAndNil(F);
end;
finally
FreeAndNil(Cert);
end;
finally
FreeAndNil(P8);
end;
end;
#12549
Posted: 02/23/2010 00:24:05
by Eugene Mayevski (EldoS Corp.)

And did you have a chance to purchase a license within this year? If no, it's right time to do this now. If yes, then please follow the instructions in the registration e-mail to assign the license ticket to your user account.


Sincerely yours
Eugene Mayevski
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 3555 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!