bestlong 怕失憶論壇
標題:
Delphi 如何將字串用 MD5 加密
[打印本頁]
作者:
bestlong
時間:
2012-12-19 09:57
標題:
Delphi 如何將字串用 MD5 加密
Delphi 從 5 ~7 版都沒有內建的函數可以直接使用。剛好有 Indy 這個元件可以幫忙解決
請去
The Indy Project
下載 Indy VCL 後安裝
然後在程式中增加下列函數
//uses IdHashMessageDigest, idHash
function STR2MD5(const ss : string) : string;
begin
with TIdHashMessageDigest5.Create do
begin
try
result := TIdHash128.AsHex(HashValue(ss));
finally
Free;
end;
end;
end;
複製代碼
這樣就可以在程式中使用了
procedure TForm1.btnRunClick(Sender: TObject);
begin
Memo1.Text := STR2MD5(edIn.Text);
Memo1.Lines.Append(STR2MD5('123'));
end;
複製代碼
歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/)
Powered by Discuz! X1.5