是HashAlgorithm.ComputeHash()状态? [英] Is HashAlgorithm.ComputeHash() stateful?

查看:125
本文介绍了是HashAlgorithm.ComputeHash()状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要独立地计算数据的多个块的哈希值。事情是这样的:

I need to compute hashes of multiple blocks of data independently. Something like this:

using( HashAlgorithm hasher = new ActualHashAlgorithm() ) {
    for( int i = 0; i = numberOfBlocks; i++ ) {
        byte[] block = getBlock( i );
        byte[] hash = hasher.ComputeHash( block );
        // use hash
    }
}

我可以重用块之间的相同 HashAlgorithm 对象?将 HashAlgorithm 重置调用之间的状态,以 ComputeHash()还是需要处置的 HashAlgorithm 对象,并创建新的数据,每一个新的块?

Can I reuse the same HashAlgorithm object between blocks? Will HashAlgorithm reset state between calls to ComputeHash() or do I need to dispose the HashAlgorithm object and create new one for each new block of data?

推荐答案

使用 ComputeHash 通常是无状态的,虽然这取决于实际的执行情况?您可以检查,在运行时通过访问国家调用 ComputeHash ...

Using ComputeHash is usually stateless although it depends on the actual implementation... you can check that at runtime by accessing State after the call to ComputeHash...

  • http://msdn.microsoft.com/en-us/library/s02tk69a.aspx
  • http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.transformblock.aspx
  • http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.transformfinalblock.aspx
  • http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.state.aspx

这篇关于是HashAlgorithm.ComputeHash()状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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