TDC_hashclasses are defined in DCPcrypt library.
another alternative is this
If you use Lazarus 1.6 and above / FPC 3.0.0 and above
then download this library at
https://github.com/Xor-el/HashLib4Pascal
locate "HashLib4PascalPackage.lpk" in the "Packages" folder of the Library.
Open it and add it to your project.
below is a simple console program calculating the HMAC specified in your post using the library above.
Enjoy. :)
Thanks Xor-el, according to your code,I use HashLib4Pascal calculate the HMAC value.
But for the result HMAC value,it's all characters in it are capital.
My result:
0F231777BD4525B250CFAD3B1A9FF539B07C3B1A4690C0EB236E73FB72D42D10166BEAF5C00E34E0A1C6B6D52CBDBAD1BA1B1760DB4E5E2677B7B09CEDBDA981
When I compare the value on line(https://www.freeformatter.com/hmac-generator.html), all characters are lower case.
Result online:
0f231777bd4525b250cfad3b1a9ff539b07c3b1a4690c0eb236e73fb72d42d10166beaf5c00e34e0a1c6b6d52cbdbad1ba1b1760db4e5e2677b7b09cedbda981
Which one is correct?How can I do for the code?
Because after HMAC,I'll do base64 encode, capital and lower case letter will get different result.
Can you help me for this?TDC_hashclasses are defined in DCPcrypt library.
another alternative is this
If you use Lazarus 1.6 and above / FPC 3.0.0 and above
then download this library at
https://github.com/Xor-el/HashLib4Pascal
locate "HashLib4PascalPackage.lpk" in the "Packages" folder of the Library.
Open it and add it to your project.
below is a simple console program calculating the HMAC specified in your post using the library above.
Enjoy. :)
Because after HMAC,I'll do base64 encode, capital and lower case letter will get different result.Its pretty useless to encode the hash first in hex and then in base64. Use base64 directly for the hash digest. This is more effective and avoids the case problem.
Its pretty useless to encode the hash first in hex and then in base64. Use base64 directly for the hash digest. This is more effective and avoids the case problem.
Another question is when I tried use:Is this the CalcHMAC from your first post? If yes, this is the raw binary hash digest as (ansi-)string. Feed this into your favorite base64 routine. But as already said: The routine is buggy because it use always a 64 byte buffer, whereas for SHA512 it must be 128 bytes. I guess the length of the CalcHMAC (your gibberisch string) has length 64.
edtHMAC.Text:=CalcHMAC(sMessage,'0110',tdcp_sha512);
The result I get is some strange characteris, so I have to change to use HashLib4Pascal(See attachment).Do you know the reason?
Another question is when I tried use:Is this the CalcHMAC from your first post? If yes, this is the raw binary hash digest as (ansi-)string. Feed this into your favorite base64 routine. But as already said: The routine is buggy because it use always a 64 byte buffer, whereas for SHA512 it must be 128 bytes. I guess the length of the CalcHMAC (your gibberisch string) has length 64.
edtHMAC.Text:=CalcHMAC(sMessage,'0110',tdcp_sha512);
The result I get is some strange characteris, so I have to change to use HashLib4Pascal(See attachment).Do you know the reason?
Its pretty useless to encode the hash first in hex and then in base64. Use base64 directly for the hash digest. This is more effective and avoids the case problem.
you are telling him to do what you told him to avoid in the beginning.??I guess you know what I mean, and I hope your library can return a byte result not only hex.
D:\Work\CRC_HASH>D:\FPC304\bin\i386-win32\fpc.exe -B THMACSHA5.PAS
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling THMACSHA5.PAS
Compiling hash.pas
Compiling btypes.pas
Compiling hmac.pas
Compiling hmacsha5.pas
Compiling sha512.pas
Compiling mem_util.pas
Linking THMACSHA5.exe
5888 lines compiled, 0.1 sec, 35360 bytes code, 2244 bytes data
D:\Work\CRC_HASH>THMACSHA5.exe
Hex: 6b7c693d28c311b510c42bb30b07a61e9eb8d21918f257105fe65f1d82df6ac9c9abf0f282c20d646fc2f5015efbe473ac79afd67c756056f60a626afd58795d
B64: a3xpPSjDEbUQxCuzCwemHp640hkY8lcQX+ZfHYLfasnJq/DygsINZG/C9QFe++RzrHmv1nx1YFb2CmJq/Vh5XQ==
you are telling him to do what you told him to avoid in the beginning.??I guess you know what I mean, and I hope your library can return a byte result not only hex.
Here a complete program with my library from http://www.wolfgang-ehrhardt.de/crchash_en.html. (I wanted to enter your example, but you supply only the images, so no copy and paste),
uses hash,hmac,hmacsha2,mem_util; const akey = 'Key'; const atext: ansistring = 'Message'; var ctx: THMAC_Context; mac: TSHA256Digest; begin hmac_SHA256_inits(ctx, akey); hmac_SHA256_updateXL(ctx, @atext[1], length(atext)); hmac_SHA256_final(ctx,mac); writeln('Hex: ', HexStr(@mac, sizeof(mac))); end.Code: [Select]D:\Work\CRC_HASH>D:\FPC304\bin\i386-win32\fpc.exe -B THMACSHA.PAS
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling THMACSHA.PAS
Compiling hash.pas
Compiling btypes.pas
Compiling hmac.pas
Compiling hmacsha2.pas
Compiling sha256.pas
Compiling mem_util.pas
Linking THMACSHA.exe
5573 lines compiled, 0.2 sec, 32784 bytes code, 1828 bytes data
D:\Work\CRC_HASH>THMACSHA.exe
Hex: 507285548137b5424eb5572c46496631b7ade8e88ac323c529fa142def26ffa1
B64: UHKFVIE3tUJOtVcsRklmMbet6OiKwyPFKfoULe8m/6E=