DataProtector.GetHashedPurpose 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立建構函式所指定之屬性值的雜湊。
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[]
包含 ApplicationName、PrimaryPurpose 及 SpecificPurposes 屬性之雜湊的位元組陣列。
範例
下列範例示範如何使用 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 會計算應用程式名稱和完整用途的哈希。 完整用途是所有 PrimaryPurpose 和 SpecificPurposes 屬性的串連。 這三個部分的前面都會加上其長度,因此可以反轉哈希。