DataProtector.GetHashedPurpose Método

Definición

Crea un hash de los valores de propiedad especificados por el constructor.

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

Devoluciones

Byte[]

Una matriz de bytes que contienen el valor hash de las propiedades ApplicationName, PrimaryPurpose y SpecificPurposes .

Ejemplos

En el ejemplo siguiente se muestra cómo usar el GetHashedPurpose método para aplicar un algoritmo hash a las propiedades de propósito para usarlas como entropía adicional. Forma parte de un ejemplo de código más grande para la DataProtector clase .

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

Comentarios

GetHashedPurpose calcula el hash del nombre de la aplicación y el propósito completo. El propósito completo es una concatenación de todas las PrimaryPurpose propiedades y SpecificPurposes . Cada una de las tres partes está precedida de su longitud para que se pueda invertir el hash.

Se aplica a