Hi. This is not really a Lazarus-specific question, and not a networking-specific question, but as I'm using Lazarus and this problem is with the Indy 10 lib so I thought this was a good place to start asking if anybody have seen this problem: I am using TIdHashMessageDigest5.HashStringAsHex to hash a string with MD5, but the resulting hex string does not match the expected string; the bytes are in the wrong order.
For example, for the string "test" the expected MD5 hash (as hex) is 098F6BCD4621D373CADE4E832627B4F6, but I'm getting CD6B8F0973D32146834EDECAF6B42726, which is similar but with each 4-bytes group reversed (in this example, 098F6BCD as CD6B8F09, 4621D373 as 73D32146, and so on).
My minimal case looks is this...
a form with two fields and a button:
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
procedure BitBtn1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
and the implementation:
uses IdHashMessageDigest;
procedure TForm1.BitBtn1Click(Sender: TObject);
VAR
MD5Hasher : TIdHashMessageDigest5;
begin
MD5Hasher := TIdHashMessageDigest5.Create;
Edit2.Text := MD5Hasher.HashStringAsHex (Edit1.Text);
FreeAndNIL (MD5Hasher);
end;
It looks like an endianess problem, but I am guessing.
I'm using Lazarus 0.9.28.2-8ubuntu1 r22277 FPC 2.4.0 i386-linux-gtk 2 (beta) in Ubuntu 10.04. The Indy version is 10.2.0.3 (which it seems a bit old).
So, has anybody faced this problem before (with MD5 or any other hashing in Indy)?
Thanks in advance,
MV