Re: Broken MD5 string representation

Giganews Newsgroups
Subject: Re: Broken MD5 string representation
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Mon, 14 May 2007

"Christian Danner" <---@---.---> wrote in message
news:hcfg4311orap16c6sv36lgjdvvha84tg…@domain.is.invalid...

> I see the cause of the problem in TIdHash.LongWordHashToHex():
<snip>
> So concerning MD5 IntToHex() is inappropriate

Would Idglobal.ByteToHex() be more appropriate?

    function TIdHashMessageDigest4.HashToHex(const AHash: TIdBytes):
String;
    var
        LValue: LongWord;
        I, J: Integer;
    begin
        Result := '';
        for I := 0 to 3 do begin
            for J := 0 to SizeOf(LongWord) do begin
                Result := Result +
ByteToHex(AHash[SizeOf(LongWord)*I+J]);
            end;
        end;
    end;

Alternatively, what about IdGlobal.ToHex(TIdBytes)?

    function TIdHashMessageDigest4.HashToHex(const AHash: TIdBytes):
String;
    var
        LBuf: TIdBytes;
    begin
        SetLength(LBuf, SizeOf(LongWord)*4);
        CopyTIdBytes(AHash, 0, LBuf, 0, Length(LBuf));
        Result := ToHex(LBuf);
    end;

Whould this also have to be applied to MD2 as well?

Gambit

Replies

In response to

Broken MD5 string representation posted by Christian Danner on Mon, 14 May 2007