Export (0) Print
Expand All

What Does the Cryptography Application Block Do?

The Cryptography Application Block consists of a facade that allows you to access the two types of providers contained within the block. These two types of providers are:

  • Hashing providers. These providers can be used to generate a hash from a value you supply, and compare two hash values. The block includes hash providers that use a range of common hashing algorithms.
  • Cryptography providers. These providers can be used to encrypt and decrypt values that you supply. The block includes cryptography providers that use a range of common encryption algorithms.

When you use the cryptography providers to encrypt a value, you can specify the value as an array of bytes, and the method will return the result as an array of bytes. Alternatively, you can specify the input value as a string, and the methods will return the result as a base-64 encoded string. The methods that decrypt values work the same way, except that string values returned by the methods are not base-64 encoded.

When you use the hashing providers to create a hash, you can specify the value to hash as an array of bytes, and the method will return the result as an array of bytes. Alternatively, you can specify the input value as a string, and the methods will return the result as a string. The methods that compare hash values accept either an array of bytes or a string, and return either true or false.

The following code shows how to encrypt and decrypt data. This code shows how to use the overloads that accept a string. This example assumes that you have resolved this class through the Enterprise Library container to inject the instance of the CryptographyManager class.


Ff664565.note(en-us,PandP.50).gifNote:
For more information on instantiating objects, see Creating and Referencing Enterprise Library Objects.


public void ExampleScenario(CryptographyManager crypto)
{
  string encryptedContentsBase64 = crypto.EncryptSymmetric("symmProvider", "SensitiveData");

  // Decrypt the base64 encoded string
  string readableString = crypto.DecryptSymmetric("symmProvider", encryptedContentsBase64);
}

For information about resolving Enterprise Library objects in your applications, see Creating and Referencing Enterprise Library Objects.


Show:
© 2014 Microsoft