DataProtector Class

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Provides the base class for data protectors.

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


type DataProtector = class end

System_CAPS_protmethodDataProtector(String, String, String[])

Creates a new instance of the DataProtector class by using the provided application name, primary purpose, and specific purposes.


Gets the name of the application.


Specifies whether the hash is prepended to the text array before encryption.


Gets the primary purpose for the protected data.


Gets the specific purposes for the protected data.

System_CAPS_pubmethodSystem_CAPS_staticCreate(String, String, String, String[])

Creates an instance of a data protector implementation by using the specified class name of the data protector, the application name, the primary purpose, and the specific purposes.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


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


Gets the Type of the current instance.(Inherited from Object.)


Determines if re-encryption is required for the specified encrypted data.


Creates a shallow copy of the current Object.(Inherited from Object.)


Protects the specified user data.


Specifies the delegate method in the derived class that the Protect method in the base class calls back into.


Specifies the delegate method in the derived class that the Unprotect method in the base class calls back into.


Returns a string that represents the current object.(Inherited from Object.)


Unprotects the specified protected data.

This class protects stored data from viewing and tampering. The access to the protected data is obtained by creating an instance of this class and using the exact purpose strings that were used to protect the data. The caller does not need a key to either protect or unprotect the data. The key is provided by the encryption algorithm.

Derived classes must override the ProviderProtect and Unprotect methods, which the DataProtector base class calls back into. They must also override the IsReprotectRequired method, which can always return true with a potential small loss of efficiency when applications refresh their database of stored cipher text. Derived classes should provide a constructor that calls the base class constructor, which sets the ApplicationName, SpecificPurposes, and PrimaryPurpose properties.

The following example demonstrates how to create a data protector that uses a protection class with an option for extra entropy. By default, the DataProtector class prepends the hash of the purpose properties to the data to be encrypted. You can turn that functionality off and use the hashed purpose as extra entropy when calling a data protector with an extra entropy option.

No code example is currently available or this language may not be supported.

The following example demonstrates a simple data protector that uses the PrependHashedPurposeToPlaintext functionality of the DataProtector class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 4.5

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top