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
Linking THMACSHA.exe
14 lines compiled, 0.1 sec, 30848 bytes code, 1764 bytes data
D:\Work\CRC_HASH>THMACSHA.exe
507285548137b5424eb5572c46496631b7ade8e88ac323c529fa142def26ffa1
If you want to calculate hmac, you can use HashLib4Pascal
https://github.com/Xor-el/HashLib4Pascal
I used it and worked
function getsha256signature(StringToSign , mykey:string):string; var LHMAC: IHMAC; begin LHMAC := THashFactory.THMAC.CreateHMAC(THashFactory.TCrypto.CreateSHA2_256); LHMAC.Key := TConverters.ConvertStringToBytes(MyKey, TEncoding.UTF8); getsha256signature := LHMAC.ComputeString(StringToSign, TEncoding.UTF8).ToString(); end;
but my app start crashing, probably due to this previous function i had:
function GetTimestamp():string; Begin GetTimestamp := inttostr(Trunc((Now - EncodeDate(1970, 1 ,1)) * 24 * 60 * 60)); end;
ANy idea if this can be done with dcpcrypt?If you want to calculate hmac, you can use HashLib4Pascal
https://github.com/Xor-el/HashLib4Pascal
@Gammatester i will try your code. Thanks!!
Yes I am the library developer.I think HashLib4Pascal is obviously the cause; i removed it from my project and i had no more troubles since then. IF your are the library developer, check why it crashes with my custom timestamp function (if i remove GetTimestamp function, then getsha256signature works and the app do not crash)
don't know why your code is crashing but HashLib4Pascal is obviously not the cause. can you upload your code so we can check the cause of the crash?
Anyway, im cleaning my code to see if something else could be wrong.
I could send you the entire project by private. So you coudl check if it is something with your library.Please Go ahead.
It'd be nice to know how this turned out.
Yes, it was a lack of error handlers in my code. I implemented all the necessary handlers and i had no more errors. Thanks Xor-el for your time :)