I'm in the process of implementing XML digital signatures. I'm starting with little steps, so right now I want to solve the problem of SHA-1 hashing.
There are lots of questions about this in SO:
- Digitially Sign Key with Lockbox
- Encryption library for Delphi
- Convert this php digital signing to Delphi
- Delphi: is there a version of LockBox for Delphi-XE
- Delphi 2010 Cryptography libraries
…and probably more. However, I'm using Delphi XE. So far, I've tried LockBox 2 (both the Songbeamer and Sourceforge versions), Lock Box 3, DCPCrypto2 and some others (Hashes is an easy to use unit which uses Windows crypto functions)
I prepared a small test rig that gives me the following:
LockBox2
FAILED: 1 ('abc')
Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')
Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
LockBox3
FAILED: 1 ('abc')
Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')
Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
DCPCrypto2
FAILED: 1 ('abc')
Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')
Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
Hashes
Test 1 passes
Test 2 passes
Have you succeeded in compile the mentioned libraries under Delphi XE and make them give the appropriate values? I'm particularly interested in DCPCrypt2 SelfTest
procedure.
Edit: I've added this answer with the fixed source code. Thank you all for your help, it is most appreciated.
Best Answer
Leonardo, i think which your problem is the
UNICODE
when you uses a function to hash astring
you are passing a array (buffer) of bytes. so when you pass theabc
string in Delphi XE, your are hashing a buffer like this61 00 62 00 63 00
(Hex representation)check this sample application which uses the Windows crypto functions from the
Jwscl library
(JEDI Windows Security Code Lib)this return
abc
AnsiStringA9993E364706816ABA3E25717850C26C9CD0D89D
abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
AnsiString84983E441C3BD26EBAAE4AA1F95129E5E54670F1 for
abc
unicode9F04F41A848514162050E3D68C1A7ABB441DC2B5
abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
Unicode51D7D8769AC72C409C5B0E3F69C60ADC9A039014