Delphi:如何计算大文件的SHA哈希 [英] Delphi: How to calculate the SHA hash of a large file

查看:126
本文介绍了Delphi:如何计算大文件的SHA哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在5 Gig文件上生成SHA。

Hi I need to generate a SHA over a 5 Gig file

您知道基于非字符串的Delphi库吗?

Do you know of a non string based Delphi library that can do this ?

推荐答案

您应使用 DCPcrypt v2 并读取缓冲的文件,并使用缓冲区为SHA哈希器提供数据,直到您读取完整的5GB文件为止。

You should use DCPcrypt v2 and read your file buffered and feed the SHA hasher with the buffer until you've read the complete 5GB file.

如果您想知道如何读取已缓冲的大文件,请参阅我的答案有关使用自定义缓冲的文件副本

If you want to know how to read a large file buffered, see my answer about a file copy using custom buffering.

所以在概念上(没有真正的delphi代码!):

so in concept (no real delphi code!):

function GetShaHash(const AFilename: String)
begin
  sha := TSHAHasher.Create;
  SetLength(Result, sha.Size);
  file := OpenFile(AFilename, GENERIC_READ);
  while not eof file do
  begin
     BytesRead := ReadFile(file, buffer[0], 0, 1024 * 1024);
     sha.Update(buffer[0], BytesRead);
  end;
  sha.Final(Result[0]); 
  CloseFile(file);
end;

这篇关于Delphi:如何计算大文件的SHA哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆