how to incorporate the Validation Application Block into your application
To prepare your application
- Add a reference to the Validation Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the Microsoft.Practices.EnterpriseLibrary.Validation.dll assembly. Select the assembly, and then click OK to add the reference.
- Use the same procedure to set a reference to the Enterprise Library Common assembly, named Microsoft.Practices.EnterpriseLibrary.Common.dll.
- Follow the same procedure to set a reference to the ObjectBuilder assembly, Microsoft.Practices.EnterpriseLibrary.ObjectBuilder 2 .dll.
- If you are using the ASP.NET, Windows Forms, or WCF integration assemblies, add one of the following references as appropriate.
- Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.dll
- Microsoft.Practices.EnterpriseLibrary.Validation.Integration.AspNet.dll
- Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.dll
- (Optional) To use elements from the Validation Application Block without fully qualifying the type with the namespace, add the following using statements (C#) or Imports statements (Visual Basic) to the top of your source code file.
C#
using Microsoft.Practices.EnterpriseLibrary.Validation; using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
Visual Basic
Imports Microsoft.Practices.EnterpriseLibrary.Validation Imports Microsoft.Practices.EnterpriseLibrary.Validation.Validators
Note:
For Visual Basic projects, you can use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer. On the Project menu, click Properties. When the Project Designer appears, click the References tab.
Posted in: .NET Framework| Tags: Reference Block Application Validation Application Block Validation Incorporate Coding Assembly Microsoft click dll integration enterpriselibraryThe Validation Application Block in Enterprise Library 4.1
The Enterprise Library Validation Application Block provides useful features that allow developers to implement structured and easy-to-maintain validation scenarios in their applications. Any application that accepts input either from users or from other systems must ensure that the information is valid in terms of some set of rules that you specify. For example, when processing an order, you may need to check that a customer's phone number has the correct number of digits or that a date falls within a particular range. In addition, if the validation fails, you may need to send an error message that explains what is wrong.
The Enterprise Library Validation Application Block provides a library of classes named validators, which implement functionality for validating .NET Framework data types. For example, one validator checks for null strings and another validator checks that a number falls within a specified range.
There are also special validators named AndCompositeValidator and OrCompositeValidator. If you create an AndCompositeValidator, which aggregates other validators, all validators in the composite validator must return T rue for successful validation. If you create an OrCompositeValidator, at least one of the validators in the composite validator must return T rue for successful validation.
You can also group validators together in a rule set. A rule set allows you to validate a complex object or graph by composing different validators of different types and applying them to elements in the object graph. Examples of these elements include fields, properties, and nested objects.
By using the Validation Application Block, you can perform validation and create rule sets in the following three ways:
- Using configuration
- Using attributes
- Using code
In addition, the Validation Application Block includes adapters that allow you to use the application block with the following technologies:
- ASP.NET
- Windows Forms
- Windows Communications Framework (WCF)
Designing for Simplified Cryptography Functionality
Cryptography in applications can be implemented in many ways. Typically, developers must duplicate code to perform common tasks. To meet the needs of their organization, they may have to familiarize themselves with many different ways of implementing cryptography. The Cryptography Application Block is designed to simplify and abstract the implementation of cryptography in applications.
Design Implications
Ensuring that the application block simplifies the task of accessing cryptography functionality resulted in the following design decisions:
It should expose only a small number of methods that a developer would need to understand.
It should accept and return data using consistent data types.
It should support common algorithms.
The following subtopics describe these decisions.
Small Number of Methods
The application block supports a small number of methods that simplify the most common cryptography tasks. It provides a Cryptographer class and the corresponding non-static CryptographyManager façade (for use with the Unity Application Block) that define the set of static methods the application block supports. These methods include the following:
CreateHash
CompareHash
EncryptSymmetric
DecryptSymmetric
Consistent Data Types
Each public method has two overloads. One overload accepts parameters as type string; the other overload accepts the parameters as a byte array. For example, the following code shows the two overloads for the CreateHash method
C# Copy Code
public static byte[] CreateHash(string hashInstance, byte[] plainText)
public static string CreateHash(string hashInstance, string plaintext)
Visual Basic Copy Code
Public Shared Function CreateHash(ByVal hashInstance As String, ByVal plainText As Byte()) As Byte()
Public Shared Function CreateHash(ByVal hashInstance As String, ByVal plainText As String) As String
Common Algorithms
The Cryptography Application Block includes two implementations of symmetric providers. The DpapiSymmetricCryptoProvider uses DPAPI to provide cryptography services. Developers can use the SymmetricAlgorithmProvider to select and configure symmetric algorithms included with the .NET Framework.
The Cryptography Application Block includes two implementations of hash providers. The KeyedHashAlgorithmProvider allows developers to configure hash algorithms included with the .NET Framework that require a generated key. The HashAlgorithmProvider allows developers to configure hash algorithms that do not require a generated key. Both providers allow the developer to ensure that a random string (known as a salt value) is generated and pre-pended to the plaintext before hashing. Consider using salt values for storing passwords, because they dramatically slow dictionary attacks as each entry in the dictionary must be hashed with each salt value.
Note:
SHA256Managed is the recommended hash algorithm; the SHA1Managed algorithm is still acceptable but not encouraged. The MD4 and MD5 algorithms are not recommended. For symmetric encryption, AES (such as Rijndael) is currently recommended; DES is no longer recommended.
The Cryptography Application Block
The Enterprise Library Cryptography Application Block simplifies how developers incorporate cryptographic functionality in their applications. Applications can use the application block for a variety of tasks, such as encrypting information, creating a hash from data, and comparing hash values to verify that data has not been altered.
The Cryptography Application Block has the following features:
It reduces the requirement to write boilerplate code to perform standard tasks; it does this by providing implementations that you can use to solve common application cryptography problems.
It helps maintain consistent cryptography practices, both within an application and across the enterprise.
It eases the learning curve for developers by using a consistent architectural model across the various areas of functionality that are provided.
It provides implementations that you can use to solve common application cryptography problems.
It is extensible; this means it supports custom implementations of cryptography providers.
This section includes the following topics:
Introduction to the Cryptography Application Block
Developing Applications Using the Cryptography Application Block
Key Scenarios
Design of the Cryptography Application Block
Extending and Modifying the Cryptography Application Block
Deployment and Operations
Cryptography QuickStart
More Information
For more information, see the following resources:
Improving Web Application Security: Threats and Countermeasures
How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
patterns & practices Security How Tos Index