HashAlgorithm 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示所有加密哈希算法实现均必须从中派生的基类。
public ref class HashAlgorithm abstract : IDisposable, System::Security::Cryptography::ICryptoTransform
public ref class HashAlgorithm abstract : IDisposable
public ref class HashAlgorithm abstract : System::Security::Cryptography::ICryptoTransform
public abstract class HashAlgorithm : IDisposable, System.Security.Cryptography.ICryptoTransform
public abstract class HashAlgorithm : IDisposable
public abstract class HashAlgorithm : System.Security.Cryptography.ICryptoTransform
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HashAlgorithm : System.Security.Cryptography.ICryptoTransform
type HashAlgorithm = class
interface IDisposable
interface ICryptoTransform
type HashAlgorithm = class
interface 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
Public MustInherit Class HashAlgorithm
Implements ICryptoTransform, IDisposable
Public MustInherit Class HashAlgorithm
Implements IDisposable
Public 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()。
Hash |
初始化 HashAlgorithm 类的新实例。 |
Hash |
表示计算所得的哈希代码的大小(以位为单位)。 |
Hash |
表示计算所得的哈希代码的值。 |
State |
表示哈希计算的状态。 |
Can |
获取一个值,该值指示是否可重复使用当前转换。 |
Can |
当在派生类中重写时,获取一个值,该值指示是否可以转换多个块。 |
Hash |
获取计算所得的哈希代码的值。 |
Hash |
获取计算所得的哈希代码的大小(以位为单位)。 |
Input |
当在派生类中重写时,获取输入块的大小。 |
Output |
当在派生类中重写时,获取输出块的大小。 |
IDisposable. |
释放由 HashAlgorithm 占用的非托管资源,还可以另外再释放托管资源。 |
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.3, 1.4, 1.6, 2.0, 2.1 |