Digital Sign Using Lockbox

I have to sign a digital string using the SHA-1 algorithm with RSA using the PKCS # 1 add-on. I downloaded Turbo Power Lockbox for use with the Delphi programming language.

In a previous question, I learned how to convert a private key from PEM format to DER format (which, if I understand ASN.1 format correctly and is used with Lockbox).

I get a division by zero error in the following code in SignString:

uses LbRSA,lbAsym,LbDSA; procedure TForm1.Button1Click(sender: TObject); var mPrivateKey: TLbRSAKey; mLbRSASSA : TLbRSASSA; begin mPrivateKey := TLbRSAKey.Create(aks1024); mPrivateKey.LoadFromFile('C:\temp\myrsakey.der'); mLbRSASSA := TLbRSASSA.create(nil); mLbRSASSA.HashMethod := hmSHA1; mLbRSASSA.PrivateKey.Assign(mprivateKey); mLbRSASSA.SignString('sign this message'); 

This is how I generated c: \ temp \ myrsakey.der:

c: \ openssl \ bin \ openssl req -x509 -nodes -days 365 -newkey rsa: 1024 -sha1 -subj "/ C = US / ST = CA / L = Mountain View / CN = www.mycompany.com" -keyout myrsakey.pem -out c: \ temp \ myrsacert.pem

Use to convert from PEM to DER:

c: \ openssl \ bin \ openssl rsa -inform PEM -outform DER -in c: \ temp \ myrsakey.pem -out c: \ temp \ myrsakey.der

Any ideas why I am getting division by zero error?

+1
source share
1 answer

The private key that you generate using OpenSSL is in a different format that Lockbox requires.
I have not figured out what is required for OpenSSL to create a Lockbox key (even if OpenSSL is capable), but judging by your previous question, you already have a key / certificate, so my first idea of ​​using Lockbox to generate a key is probably useless:

  mLbRSASSA := TLbRSASSA.create(nil); mLbRSASSA.KeySize := aks1024; mLbRSASSA.GenerateKeyPair; mLbRSASSA.PrivateKey.StoreToFile(mykeyname); 

However, perhaps the best suggestion is that you could completely avoid Lockbox. I stopped using Lockbox and now use the OpenSSL / dll library directly for signing, etc. Using Marco Ferrante's work: http://www.disi.unige.it/person/FerranteM/delphiopenssl/
There are good examples, and it all starts to make sense as soon as you combine it with reading OpenSSL documents.

+2
source

All Articles