Autor Beitrag
anno2007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 03.01.11 21:30 
Hey,
ich lese eine Datei als String ein, und übergebe dann einen Teil des Strings an diese Funktion:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function MD5String(const Input:string):string;
var
    IDMD5:TIdHashMessageDigest5;
begin
    IDMD5:=TIdHashMessageDigest5.Create;
    try
        Result:=LowerCase(IDMD5.HashStringAsHex(Input));
    finally
        IDMD5.Free;
    end;
end;


Leider sind in den Strings Steuerzeichen drin und es kommt irgendwie ein anderer MD5 Hash dabei raus, als PHP liefert.
Irgendwie werden die Zeichen anders interpretiert als in PHP.
Hat da jemand ne Idee?

Danke,
anno2007 :)


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Mo 03.01.2011 um 22:50
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 03.01.11 21:39 
Ich tippe eher darauf, dass da was mit Delphi XE und Unicode durcheinander kommt. Schau dir mal die MD5-Methoden an - die müsstest du auf AnsiString umschreiben, damit PHP dasselbe liefert wie das neue Delphi.

_________________
We are, we were and will not be.
anno2007 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 03.01.11 21:49 
Hmm,
ok danke.

Ich weis nicht ob ich das hinbekomme da was umzuschreiben weil ich zu wenig Ahnung davon habe.
Naja ich probiere es.

Danke für die Antwort.


/Edit:

Hier hab ich übrigens die Lösung gefunden (falls jemanden noch interessieren sollte):
stackoverflow.com/qu...shing-in-delphi-2009

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
uses Types, MessageDigest_5;

procedure TForm16.Edit1Change(Sender: TObject);
var
  MD5: IMD5;
begin
  MD5 := GetMD5;
  MD5.Init;
  MD5.Update(TByteDynArray(RawByteString(Edit1.Text)), Length(RawByteString(Edit1.Text)));
  Edit2.Text := LowerCase(MD5.AsString);
end;