DataProtector.GetHashedPurpose 方法

定义

创建由构造函数指定的属性值的哈希。

protected:
 virtual cli::array <System::Byte> ^ GetHashedPurpose();
protected virtual byte[] GetHashedPurpose ();
abstract member GetHashedPurpose : unit -> byte[]
override this.GetHashedPurpose : unit -> byte[]
Protected Overridable Function GetHashedPurpose () As Byte()

返回

Byte[]

包含 ApplicationNamePrimaryPurposeSpecificPurposes 属性的哈希的字节数组。

示例

以下示例演示如何使用 GetHashedPurpose 方法对用作额外熵的用途属性进行哈希处理。 它是 类的更大代码示例的 DataProtector 一部分。

// To allow a service to hand out instances of a DataProtector we demand unrestricted DataProtectionPermission
// in the constructor, but Assert the permission when ProviderProtect is called.  This is similar to FileStream
// where access is checked at time of creation, not time of use.
[SecuritySafeCritical]
[DataProtectionPermission(SecurityAction.Assert, ProtectData = true)]
protected override byte[] ProviderProtect(byte[] userData)
{
    // Delegate to ProtectedData
    return ProtectedData.Protect(userData, GetHashedPurpose(), Scope);
}
' To allow a service to hand out instances of a DataProtector we demand unrestricted DataProtectionPermission 
' in the constructor, but Assert the permission when ProviderProtect is called.  This is similar to FileStream
' where access is checked at time of creation, not time of use.
<SecuritySafeCritical(), DataProtectionPermission(SecurityAction.Assert, ProtectData:=True)> _
Protected Overrides Function ProviderProtect(ByVal userData() As Byte) As Byte()
    ' Delegate to ProtectedData
    Return ProtectedData.Protect(userData, GetHashedPurpose(), Scope)

End Function 'ProviderProtect

注解

GetHashedPurpose 计算应用程序名称和完整用途的哈希。 完整用途是连接所有 PrimaryPurposeSpecificPurposes 属性。 这三个部分的前面都有其长度,因此哈希可以反转。

适用于