- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用时 MD5CryptoServiceProvider
我发现它可能需要处理,因为它继承自 HashAlgorithm
实现 IDisposable
的类.然而,the example in the docs没有处置它。
我的问题是为什么HashAlgorithm
类实现 IDisposable
?散列不只是在内存中进行的一些计算吗?什么样的非托管资源可以用于散列?
最佳答案
你可以看看sources
[System.Security.SecuritySafeCritical] // overrides public transparent member
protected override void Dispose(bool disposing)
{
if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
_safeHashHandle.Dispose();
base.Dispose(disposing);
}
SafeHashHandle
实例,用于包装非托管资源(操作系统句柄)并调用
Dispose
从基地
HashAlgorithm
类(class)。您必须在使用后正确处置和释放此句柄
[System.Security.SecurityCritical]
protected override bool ReleaseHandle()
{
FreeHash(handle);
return true;
}
ReleaseHandle()
来自基础的方法
SafeHandle
类(class)。您可以在
MSDN 阅读有关该类(class)的更多信息,基本上这个类是任何操作系统资源的包装器
It contains a critical finalizer that ensures that the handle is closed and is guaranteed to run during unexpected AppDomain unloads, even in cases when the platform invoke call is assumed to be in a corrupted state.
关于c# - 为什么 HashAlgorithm 类要实现 IDisposable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59083838/
我正在尝试将充气城堡用于 DTLS 握手。 我按照 this link 生成了 key .我正在通过扩展 DefaultTlsClient 来工作。它可以生成client_hello 数据包。但是当
我无法得到关于这个问题的明确答案,所以这个问题。过去很少有 SO 帖子提到 HashAlgorithm 的实例在 MSDN 文档中不是线程安全的引用片段。 见 Why does SHA1.Comput
从 HashAlgorithm 派生的对象(例如 MD5CryptoServiceProvider)具有 Dispose() 方法,但它是私有(private)的。相反,它有一个 Clear() 方法
我有一个散列算法对象(在本例中为 SHA1),我向其提供数据,以便在调用 Result 属性时最终获得散列结果。 问题是一旦调用了 m_HashAlgorithm.Hash 属性,该对象就不能再用于喂
我需要独立计算多个数据 block 的哈希值。像这样: using( HashAlgorithm hasher = new ActualHashAlgorithm() ) { for( int
使用时 MD5CryptoServiceProvider我发现它可能需要处理,因为它继承自 HashAlgorithm实现 IDisposable 的类.然而,the example in the d
方法 HashAlgorithm.TransformBlock 接受参数 outputBuffer和 outputOffset . 我想不出这个方法有这些的原因。将散列数据复制到某个地方以至于该副本成
我有以下用例: 从一个文件中读取n个字节 计算这 n 个字节的 (MD5) 散列 从文件中读取下m个字节 为最多 n+m 字节的文件计算 (MD5) 哈希 增量散列文件不是问题,just call T
所以我想知道哈希算法的各种实现之间是否存在重大差异,以SHA系列算法为例。它们每个都有 3 个实现,1 个在托管代码中,2 个围绕不同的 native 加密 API 进行包装,但是使用它们之间有什么主
我似乎看到 SHA-2 以两种不同的方式完成。 是的,我知道 1 是“新的”(实例化的),而另一个是 Create 方法,但它似乎实现了相同的相同对象 HashAlgorithm sha2 = new
我需要在 C# 中使用 salt 对密码进行哈希处理。 salt是从一个来源获取的,类型是byte[],password是从另一个来源获取的,类型是String。 计算一个区 block 的哈希值非常
我想了解散列算法的工作原理,特别是 SHA3-512。为了了解它是如何工作的,我在 Google 中搜索了代码并找到了 Hashlib。 .该代码不起作用,因为我没有 Hashlib 库(不确定应该调
这两个代码块返回相同的东西吗?假设 arr 在两个例子中都是相同的 byte[]: 代码示例 1 HashAlgorithm a = HashAlgorithm.Create("SHA-256");
这两个代码块返回相同的东西吗?假设 arr 在两个例子中都是相同的 byte[]: 代码示例 1 HashAlgorithm a = HashAlgorithm.Create("SHA-256");
我正在使用 spymemcached 和 HashAlgorithm.KETAMA_HASH 连接到 5 个节点的 memcached 池。 我的理解是,当我们使用一致的哈希算法时,例如,当节点关闭时
HashAlgorithm.TransformBlock() 具有 outputBuffer 参数,该参数记录为 用于计算哈希码的输入数组部分的副本。 这听起来像是我的数据将被读取,用于更改哈希机制状
我有一个 ASP.Net MVC 项目,它在使用 HashAlgorithm 时运行良好,但我试图在 ASP.NET Core 2 中复制同一个项目,但出现以下错误: System.PlatformN
我是一名优秀的程序员,十分优秀!