Export (0) Print
Expand All

DataProtector.GetHashedPurpose Method

.NET Framework 4.5

Creates a hash of the property values specified by the constructor.

Namespace:  System.Security.Cryptography
Assembly:  System.Security (in System.Security.dll)

protected virtual byte[] GetHashedPurpose()

Return Value

Type: System.Byte[]
An array of bytes that contain the hash of the ApplicationName, PrimaryPurpose, and SpecificPurposes properties.

GetHashedPurpose computes the hash of the application name and the full purpose. The full purpose is a concatenation of all the PrimaryPurpose and SpecificPurposes properties. Each of the three parts is prefaced with its length so the hash can be reversed.

The following example shows how to use the GetHashedPurpose method to hash the purpose properties for use as extra entropy. It is part of a larger code example for the DataProtector class.

// 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);
}

.NET Framework

Supported in: 4.6, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft