行路之马 發表於 2023-5-24 16:36:00

delphi 获取MD5

<h1 id="获取md5">获取MD5</h1>
<h2 id="代码">代码</h2>
<pre><code class="language-delphi">uses
System.Hash;

procedure TForm1.Button1Click(Sender: TObject);
var
vStream: TMemoryStream;
vBytes: TBytes;
I: Integer;
begin
//获取字符串的MD5值
Memo1.Lines.Add(THashMD5.GetHashString('测试数据'));
//获取文件的MD5值
Memo1.Lines.Add(THashMD5.GetHashStringFromFile('C:\Users\Administrator\Desktop\ceshi.db'));
//获取流的MD5值
vStream := TMemoryStream.Create;
try
    vStream.LoadFromFile('C:\Users\Administrator\Desktop\ceshi.db');
    Memo1.Lines.Add(THashMD5.GetHashString(vStream));
finally
    vStream.Free;
end;
//获取字符串的MD5字节数组
Memo1.Lines.Add('----------------');
vBytes := THashMD5.GetHashBytes('测试数据');
for I := Low(vBytes) to High(vBytes) do
    Memo1.Lines.Add(vBytes.ToHexString);
end;
</code></pre>
<h2 id="方法">方法</h2>
<h3 id="systemhashthashmd5gethashstringfromfile">System.Hash.THashMD5.GetHashStringFromFile</h3>
<pre><code class="language-delphi">class function GetHashStringFromFile(const AFileName: TFileName): string;
</code></pre>
<p><strong>unit</strong></p>
<p>System.Hash</p>
<p>从指定的文件创建哈希摘要,并将创建的摘要的值作为十六进制的字符串返回。</p>
<h3 id="systemhashthashmd5gethashstring">System.Hash.THashMD5.GetHashString</h3>
<pre><code class="language-delphi">class function GetHashString(const AString: string): string;
class function GetHashString(const AStream: TStream): string;
</code></pre>
<p><strong>unit</strong></p>
<p>System.Hash</p>
<p>从指定的输入值创建哈希摘要,并将创建的摘要的值作为十六进制的字符串返回。</p>
<h3 id="systemhashthashmd5gethashbytes">System.Hash.THashMD5.GetHashBytes</h3>
<pre><code class="language-delphi">class function GetHashBytes(const AData: string): TBytes;
class function GetHashBytes(const AStream: TStream): TBytes;
</code></pre>
<p><strong>unit</strong></p>
<p>System.Hash</p>
<p>从指定的输入值创建哈希摘要,并将创建的摘要的值返回为字节数组。</p>
<h3 id="systemhashthashmd5gethashbytesfromfile">System.Hash.THashMD5.GetHashBytesFromFile</h3>
<pre><code class="language-delphi">class function GetHashBytesFromFile(const AFileName: TFileName): TBytes;
</code></pre>
<p><strong>unit</strong></p>
<p>System.Hash</p>
<p>从指定的文件创建哈希摘要,并将创建的摘要的值返回为字节数组。</p><br><br>
来源:https://www.cnblogs.com/txgh/p/17428771.html
頁: [1]
查看完整版本: delphi 获取MD5