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