我同意 Henk Holterman 的回应。您必须自己进行拆分。但是,您可以做的是不使用单个 ComputeHash 调用来计算完整的哈希,而是通过TransformBlock
调用以字节块的形式进行计算。有关示例,请参见此处。
有了这个,您可以自己实例化一个大小的缓冲区,并将其作为参数提供给随后的并行 TransformBlock 调用。
编辑:这是一些完成工作的代码
static void Hash2Md5inParallel()
{
string strFullPath = YourFilePathGoesHere;
byte[] Buffer = new Byte[1000]; //Instantiate Buffer to copy bytes.
byte[] DumpBuffer = new Byte[1000]; //Send output to bin.
System.Security.Cryptography.MD5 md5_1 = new System.Security.Cryptography.MD5CryptoServiceProvider();
System.Security.Cryptography.MD5 md5_2 = new System.Security.Cryptography.MD5CryptoServiceProvider();
System.IO.FileStream file = new System.IO.FileStream(strFullPath, FileMode.Open);
file.Seek(1000, SeekOrigin.Begin); //skip some chars if need be
int BytesToHash = 0;
do
{
BytesToHash = file.Read(Buffer, 0, 1000);
md5_1.TransformBlock(Buffer, 0, BytesToHash, DumpBuffer, 0);
//enter some code to skip some bytes for the other hash if you like...
md5_2.TransformBlock(Buffer, 0, BytesToHash, DumpBuffer, 0);
}
while (BytesToHash > 0); //Repeat until no more bytes.
//call TransformFinalBlock to finish hashing - empty block is enough
md5_1.TransformFinalBlock(new byte[0], 0, 0);
md5_2.TransformFinalBlock(new byte[0], 0, 0);
//Get both Hashs.
byte[] hash1 = md5_1.Hash;
byte[] hash2 = md5_2.Hash;
}