可能重复:
在C#中散列SHA1大文件(超过2GB)
我有一个大型文件的大文件,它给我错误"抛出类型'System.OutOfMemoryException'的异常."
任何人都有解决此问题的想法或解决方案.请帮忙.示例代码....
private string GetSha1()
{
string filePath = txtFileName.Text;
byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
byte[] hashValue;
SHA1Managed hashString = new SHA1Managed();
string hex = "";
hashValue = hashString.ComputeHash(filebytes);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex;
}
Run Code Online (Sandbox Code Playgroud)
我在上面的代码中在下面的行中得到例外....
byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
Run Code Online (Sandbox Code Playgroud)
filePath的文件大小> 500MB.
L.B*_*L.B 13
而不是将整个文件读入内存只需将流传递给ComputeHash
using(var file = File.Open(path,FileMode.Open))
{
hashValue = hashString.ComputeHash(file);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3058 次 |
| 最近记录: |