Object Pascal is my favorite language. I don’t know why people prefer C++, I find it redundant and confusing. Sometimes I must write code in C++ I don’t find it hard but linking always gave me a headache. The best part about C++ is that there are many libraries for it and one of the libraries I use the most is openssl.
So there I am I want to use openssl but with my favorite language. I want to create a simple application to sign a document and then check the signature. Of course I am not going to reinvent the wheel, I will try to use openssl.
I Google a bit and I find two solutions to my problem :
Hmm…Lockbox is great I mean great It has all sorts of functions for encrypting decrypting signing it has both native implementation and openssl wrapper but as always I hate components. Units yeah are ok but components never liked them. Why ? Well I do know why I was raised in this spirit but I hate to drag something on a form and don’t have a clue what it does. Even if you use a library using it helps you to understand what you are doing there.Components are pretty standard and with time they might get unsupported by your compiler of use and there you will forced to deal the cruel reality.
So I downloaded the openssl wrapper for Delphi, damn it was old.Well I am not trying to launch a rocket into space I am just trying to make a simple signature verification tool.
So I updated the unit added some functions that were neglected after some good hours of making it work.
And I have crated my own unit to handle the generation of the keys loading the keys signing and verifying the signature.
Attached you will find what It came up. Hope you will find it useful
Hi
I found your site on google while searching for a way to sign a string with RSA and a 1024bit Private+Public key pair.
I should mention I had never, before today, even knew what RSA was.
I made this function out of your demo, but it raises an exception when signings.
What do you think I’m doing wrong?
function HashSign(Dados:String):String;
var
rssa : pRSA;
publicKey,privateKey : pEVP_PKEY;
sign : TSignature;
data,data2 : Pchar;
begin
Data:=PChar(Dados);
OpenSSLInit();
rssa := GenKeys;
privateKey := LoadKeyFromFile
(‘E:\Dropbox\Certificação\AmPOS_Priv.pem’,”);
sign := SignData(Data,Length(Data),privateKey);
publicKey := LoadKeyFromFile
(‘E:\Dropbox\Certificação\AmPOS_Pub.pem’,”);
if VerifyData(data,Length(PChar(Dados)),publicKey,sign)
= Valid
then Result:=String(Data)
else Result:=’0′;
end;
Thank you for your attention
Nuno Picado
If you can send me the source on my e-mail octav.scurtu@ o p c 0 d e. i n f o . I will try to fix it for you!