代码
unit md5;
// -----------------------------------------------------------------------------------------------
interface
// -----------------------------------------------------------------------------------------------
uses
Windows, Classes, SysUtils;
type
TProgressEvent = procedure (aPercent: Integer) of object;
MD5Count = array[0..1] of DWORD;
MD5State = array[0..3] of DWORD;
MD5Block = array[0..15] of DWORD;
MD5CBits = array[0..7] of byte;
MD5Digest = array[0..15] of byte;
MD5Buffer = array[0..63] of byte;
MD5Context = record
State: MD5State;
Count: MD5Count;
Buffer: MD5Buffer;
end;
procedure MD5Init(var Context: MD5Context);
procedure MD5Update(var Context: MD5Context; Input: pAnsiChar; Length: longword);
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
function StrToMD5(M: AnsiString): MD5Digest;
function ViewMD5(D: MD5Digest): AnsiString;
function StrToMD5Str(M: AnsiString): AnsiString;
function FileToMD5(const aFileName: String; aProgress: TProgressEvent): MD5Digest;
function FileToMD5Str(const aFileName: String; aProgress: TProgressEvent = nil): string;
function MatchMD5(D1, D2: MD5Digest): boolean;
function DecryptMD5(Decryptstr: AnsiString): AnsiString;
function EncryptMD5(Encyptstr: AnsiString): AnsiString;
function MD5Print(D: MD5Digest): AnsiString;
const
MD5_16_0 = '0000000000000000';
// -----------------------------------------------------------------------------------------------
implementation
// -----------------------------------------------------------------------------------------------
var
PADDING: MD5Buffer = (
$80, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00
);
function DecryptMD5(Decryptstr: AnsiString): AnsiString;
begin
Result := StrToMD5Str(Decryptstr);
end;
function EncryptMD5(Encyptstr: AnsiString): AnsiString;
begin
Result := StrToMD5Str(Encyptstr);
end;
function F(x, y, z: DWORD): DWORD;
begin
Result := (x and y) or ((not x) and z);
end;
function G(x, y, z: DWORD): DWORD;
begin
Res

这是一个使用Delphi实现的MD5哈希算法,包括MD5初始化、更新、最终化等核心过程,以及文件到MD5的转换功能。代码提供了将字符串和文件转化为MD5摘要的函数,用于数据完整性校验。
最低0.47元/天 解锁文章
487

被折叠的 条评论
为什么被折叠?



