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 方法來雜湊目的屬性,以做為額外的 Entropy。 它是 類別較大程式碼範例的 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 屬性的串連。 這三個部分的前面都會加上其長度,因此可以反轉雜湊。

適用於