EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElHashFunction

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#15576
Posted: 01/21/2011 02:00:06
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

Hello!

I have a question. When I calculate the hash of file it returns different value than the online calculation. My function is
Code
Function TFeRacun.IzracunHash(FileName:String):string;
var
  Func : TElHashFunction;
  F : TFileStream;
  Dgst : BufferType;
  WTemp,WTemp1:string;
begin
  F := TFileStream.Create(Filename, fmOpenRead);
  try
    Func := TElHashFunction.Create(SB_ALGORITHM_DGST_SHA1);
    try
      Func.Reset;
      Func.Update(F);
      Dgst := Func.Finish();
    finally
      FreeAndNil(Func);
    end;              
    Wtemp:=BinaryToString(Dgst);
    Result :=Wtemp;
  finally
    FreeAndNil(F);
  end;
end;


I use online calculation on web page <a href="http://www.fileformat.info/tool/hash.htmurl">Link 1</a> and <a href="http://www.fileformat.info/tool/md5sum.htm">Link 2</a>.
MY value is "7EB5399AEAB0A2095F6FC03A8F3A6AF5AC8D8F6D", the value on web sites is "b247cef78ac52b9f15c37f973f481b86b9e60656".
Why are values different? What am I doing wrong?
Thank's for reply.

Sašo
#15577
Posted: 01/21/2011 02:32:32
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi. Hm, how you made it compile? ElHashFunction has only .UpdateStream method to hash a stream, .Update() can work only with pointer to data.
#15578
Posted: 01/21/2011 02:35:50
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Update: .UpdateStream appeared only in the latest build. However, there can be other issue - did you call .SetLicenseKey() before hashing?
#15579
Posted: 01/21/2011 02:37:08
by Vsevolod Ievgiienko (EldoS Corp.)

You should also check if SetLicenseKey is called before hash calculation.
#15580
Posted: 01/21/2011 02:40:08
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

I found this function on forum. I use delphi 7 and there is only .Update method, no .UpdateStream method.

Sašo
#15581
Posted: 01/21/2011 02:43:33
by Vsevolod Ievgiienko (EldoS Corp.)

Thats ok because Update for streams was renamed to UpdateStream only in the last SBB build. You seem to use the older one. Did you check SetLicenseKey?
#15582
Posted: 01/21/2011 02:50:41
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

I have the latest verison-8.1.192.
#15583
Posted: 01/21/2011 03:01:07
by Vsevolod Ievgiienko (EldoS Corp.)

We are talking about 8.2.193 beta where the function was renamed. In 8.1.192 there is only Update function for both buffer and stream processing, so you code is correct. The only reason for wrong hash calculation is that you might have forgotten to set license key before the calculations.
#15584
Posted: 01/21/2011 03:04:05
by Vsevolod Ievgiienko (EldoS Corp.)

P.S. It is not necessary to call Func.Reset before Func.Update. You can remove it.
#15585
Posted: 01/21/2011 03:18:25
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

Ok, I remove the reset function.
The problem was in licence key. I didn't know that I have to set it in the procedure, I thought that if I set it onFormCreate it will be set for all the functions and procedures on that form.
Thank's.

Sašo
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 3531 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!