Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 21.03.09 15:17 
Hallo.

Ich verwende in meinen Programmen eine kleine Unit mit dem Namen "md5.pas" um Dateien und Strings mit MD5 zu hashen.
Da MD5 ja nicht mehr so ganz toll ist, würde ich gerne auf SHA1 oder andere sichere Hashes umschwenken und dabei gerne den Komfor wie bei der MD3 Unit behalten. Da ging das mit hash := md5print(md5string('bla'));

Wie kann ich denn einfach und mit wenigen Zeilen Code einen String und eine Datei mit SHA1 oder besser hashen?

Danke,
Matze

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 21.03.09 16:09 
Ich nutze immer ganz gerne das DEC vom Hagen/negaH. Gabs mal bei Luckie einen Mirror, der sollte entweder hier oder in der DP zu finden sein ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var h: THash_SHA1;
begin
  h:= THash_SHA1.Create;
  try
    h.Init;
    while not Data.eof do
      h.Calc(Data.GiveMeAChunk,Data.ThisChunkSize)
    h.Done;
    result:= h.DigestStr(TFormat_HEX);
  finally
    h.Free;
  end;
end;

Keine Garantie für nix, müsste aber funktionieren ;)

EDIT: für strings geht das sogar noch einfacher.

ausblenden Delphi-Quelltext
1:
Hash:= THash_SHA1.CalcBinary(String, TFormat_HEX);					

;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Fr 27.03.09 09:00 
Danke. Das werde ich mal ausprobieren.

_________________
In the beginning was the word.
And the word was content-type: text/plain.