DataProtector.GetHashedPurpose Metodo

Definizione

Viene creato un hash dei valori delle proprietà specificate dal costruttore.

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()

Restituisce

Byte[]

Una matrice di byte che contengono l'hash delle proprietà ApplicationName, PrimaryPurpose e SpecificPurposes.

Esempio

Nell'esempio seguente viene illustrato come usare il GetHashedPurpose metodo per eseguire l'hashing delle proprietà di scopo da usare come entropia aggiuntiva. Fa parte di un esempio di codice più ampio per la DataProtector classe .

// 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

Commenti

GetHashedPurpose calcola l'hash del nome dell'applicazione e lo scopo completo. Lo scopo completo è una concatenazione di tutte le PrimaryPurpose proprietà e SpecificPurposes . Ognuna delle tre parti è preceduta dalla lunghezza in modo che l'hash possa essere invertito.

Si applica a