在WinRT / Metro中增量哈希 [英] Incremental Hashing in WinRT/Metro
本文介绍了在WinRT / Metro中增量哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我移植了一些使用增量SHA-1的代码:
I'm porting some code that uses incremental SHA-1 heavily:
SHA1 hasher = HashAlgoFactory.Create<SHA1>();
hasher.Initialize();
DiskIOCallback readCallback = null;
readCallback = delegate(bool successful) {
if (successful)
hasher.TransformBlock(hashBuffer, 0, count, hashBuffer, 0);
offset += count;
if (!successful || offset == endOffset)
{
object hash = null;
if (successful)
{
hasher.TransformFinalBlock(hashBuffer, 0, 0);
hash = hasher.Hash;
}
我正在寻找一个WinRT /我已经使用hasher.HashData之前;有没有一些相对简单的方法从HashData获取增量行为,或者一些替代实现与上述相同的功能(在WinRT / Metro方式)?这完全可能是我缺少明显的东西...
And am looking for a WinRT/Metro equivalent. I've used hasher.HashData before; is there some relatively simple way to get incremental behaviour out of HashData, or some alternative that implements the same functionality as above (in a WinRT/Metro way)? It's entirely possible I'm missing something obvious...
推荐答案
你应该使用 CryptographicHash 类:
var hashProvider = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1);
var hasher = hashProvider.CreateHash();
您可以附加多个增量的数据:
You can append multiple increments of data:
hasher.Append(bytesPart.AsBuffer());
完成后,您可以检索散列:
Once you're done, you retrieve the hash:
var hash = hasher.GetValueAndReset().ToArray();
这篇关于在WinRT / Metro中增量哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文