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[]

ApplicationNamePrimaryPurpose、および SpecificPurposes の各プロパティのハッシュを格納するバイトの配列。

次の例では、 メソッドを 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 は、アプリケーション名と完全な目的のハッシュを計算します。 完全な目的は、すべての プロパティと SpecificPurposes プロパティをPrimaryPurpose連結したものです。 3 つの各部分の前に長さが付いているため、ハッシュを元に戻すことができます。

適用対象