Extending the Cryptography Application Block

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The Cryptography Application Block is designed to be used in a variety of applications and to be a general-purpose application block. Extension points let you adapt the application block to suit the needs of any particular application. You can extend the capabilities of the application block by adding custom cryptography providers. Typically, these custom providers are third-party cryptography providers.

To extend the Cryptography Application Block

Create a new custom class and add it to your project.

Make sure the class implements the required interfaces, constructors, and methods.

Configure the generic provider in the Enterprise Library configuration tools:

  • Specify your custom class as the type name.
  • Specify any custom configuration properties by modifying the attributes of the object.

To create a custom hash algorithm provider

  1. Create a new class, and then add it to your project.
  2. (Optional) To use elements without fully qualifying the element reference, you can add the following using statement (C#) or Imports statement (Visual Basic) to the top of your source code file.
  3. Specify that the class implements IHashProvider.
  4. Add the class attribute ConfigurationElementType. Specify the type CustomHashProviderData as the attribute parameter.
  5. Add a constructor that has a parameter of type NameValueCollection.
  6. Add the CreateHash and CompareHash methods to your class, and then implement the required behavior.

To create a custom symmetric encryption algorithm provider

  1. Create a new class, and then add it to your project.
  2. (Optional) To use elements without fully qualifying the element reference, you can add the following using statement (C#) or Imports statement (Visual Basic) to the top of your source code file.
  3. Specify that the class implements ISymmetricCryptoProvider.
  4. Add the class attribute ConfigurationElementType. Specify the type CustomSymmetricCryptoProviderData as the attribute parameter.
  5. Add a constructor that has a parameter of type NameValueCollection.
  6. Add the Encrypt and Decrypt methods to your class, and then implement the required behavior.