HashAlgorithm 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示必须从中派生加密哈希算法的所有实现的基类。
public ref class HashAlgorithm abstract : System::Security::Cryptography::ICryptoTransform
public ref class HashAlgorithm abstract : IDisposable
public abstract class HashAlgorithm : System.Security.Cryptography.ICryptoTransform
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HashAlgorithm : System.Security.Cryptography.ICryptoTransform
public abstract class HashAlgorithm : IDisposable
type HashAlgorithm = class
interface ICryptoTransform
interface IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type HashAlgorithm = class
interface ICryptoTransform
interface IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type HashAlgorithm = class
interface IDisposable
interface ICryptoTransform
type HashAlgorithm = class
interface IDisposable
type HashAlgorithm = class
interface IDisposable
interface ICryptoTransform
Public MustInherit Class HashAlgorithm
Implements ICryptoTransform
Public MustInherit Class HashAlgorithm
Implements IDisposable
- 继承
-
HashAlgorithm
- 派生
- 属性
- 实现
示例
下面的代码示例计算数组的 SHA256 哈希。 此示例假定有一个预定义的字节数组 dataArray[]。
SHA256是HashAlgorithm的派生类。
HashAlgorithm sha = SHA256.Create();
byte[] result = sha.ComputeHash(dataArray);
Dim sha As SHA256 = SHA256.Create()
Dim result As Byte() = sha.ComputeHash(dataArray)
注解
哈希函数是新式加密的基础。 这些函数将任意长度的二进制字符串映射到固定长度的小二进制字符串,称为哈希值。 加密哈希函数具有计算上不可行的属性,它无法找到哈希到相同值的两个不同的输入。 哈希函数通常用于数字签名和数据完整性。
哈希用作表示大量数据的固定大小的唯一值。 如果相应的数据也匹配,则两组数据集的哈希应匹配。 对数据的小更改会导致哈希中出现大量不可预知的更改。
由于 SHA-1 冲突问题,Microsoft建议基于 SHA-256 或更高版本的安全模型。
实施者说明
从 HashAlgorithm 类继承时,必须重写以下成员: HashCore(Byte[], Int32, Int32) 和 HashFinal()。
构造函数
| 名称 | 说明 |
|---|---|
| HashAlgorithm() |
初始化 HashAlgorithm 类的新实例。 |
字段
| 名称 | 说明 |
|---|---|
| HashSizeValue |
表示计算哈希代码的大小(以位为单位)。 |
| HashValue |
表示计算的哈希代码的值。 |
| State |
表示哈希计算的状态。 |
属性
| 名称 | 说明 |
|---|---|
| CanReuseTransform |
获取一个值,该值指示是否可以重复使用当前转换。 |
| CanTransformMultipleBlocks |
在派生类中重写时,获取一个值,该值指示是否可以转换多个块。 |
| Hash |
获取计算的哈希代码的值。 |
| HashSize |
获取计算哈希代码的大小(以位为单位)。 |
| InputBlockSize |
在派生类中重写时,获取输入块大小。 |
| OutputBlockSize |
在派生类中重写时,获取输出块大小。 |
方法
显式接口实现
| 名称 | 说明 |
|---|---|
| IDisposable.Dispose() |
释放由托管资源使用 HashAlgorithm 的非托管资源,并选择性地释放托管资源。 |