DataProtector.ProviderProtect(Byte[]) Method

Definition

Specifies the delegate method in the derived class that the Protect(Byte[]) method in the base class calls back into.

C#
protected abstract byte[] ProviderProtect(byte[] userData);

Parameters

userData
Byte[]

The data to be encrypted.

Returns

Byte[]

A byte array that contains the encrypted data.

Examples

The following example shows an implementation of the ProviderProtect method. It is part of a larger code example for the DataProtector class.

C#
// 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
    ProtectedMemory.Protect(userData, Scope);
    return userData;
}

Applies to

Product Versions
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1