Cryptography Application block in Enterprise Library 5.0 (part 2)

Posted by in .NET Framework category on for Beginner level | Points: 250 | Views : 14775 red flag
Rating: 4.83 out of 5  
 6 vote(s)

Application blocks in enterprise library 5.0 simplifies the application development.....


In the last article( Encryption and Decryption using Cryptography Application block in Enterprise Library 5.0(part 1))we saw encryption and decryption using symmetric cryptography providers. Now we will see the use of hash providers.

Using a Hash Provider to Store a One-Way Hashed Text

Here we use a one-way hashing algorithm to encrypt a string. So first we have to configure web.config. Select " Add cryptography Settings" from the block menu as shown below:

Click the plus sign icon in the Hash Providers column, point to Add Hash Providers, and click Add Hash Algorithm Provider.

A dialog box is displayed. Expand the mscorlib entry until you see a list of providers, and select SHA1Managed. Then click OK.

Back in the configuration tool, change the Name property of the hashing provider. In my example I changed the name to SHA1(not in the picture). Salt Enabled property is set to True.

Save the application configuration.

Now the code

First add the reference:

? Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">




<form id="form1" runat="server">


<asp:TextBox runat="server" ID="txt1"></asp:TextBox>

<asp:Button runat="server" ID="btn1" text="submit" onclick="btn1_Click"/><br />

<asp:Label ID="lbl1" runat="server" />






using System;

using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

public partial class _Default : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)



protected void btn1_Click(object sender, EventArgs e)


string Hash = "SHA1";

string plainText = txt1.Text;

lbl1.Text = Cryptographer.CreateHash(Hash, plainText);




Hope this article helps you.................

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Nitha Deepak
Member Level: Bronze
Member Status: Member
Member Since: 4/21/2011 4:47:37 AM
Country: India
Nitha Deepak

Login to vote for this post.

Comments or Responses

Posted by: Susanthampy on: 5/18/2011 | Points: 25
Nice article Nitha
Posted by: Susanthampy on: 5/18/2011 | Points: 25
Nice article Nitha
Posted by: Nithadeepak on: 5/18/2011 | Points: 25
Thanks Susan
Posted by: Ninilcr on: 6/2/2011 | Points: 25
Good one ...
Posted by: Nithadeepak on: 6/14/2011 | Points: 25
Thanks Ninil
Posted by: CS1401 on: 7/5/2011 | Points: 25
hey netha.. i am interested in crypt.. can you give your email id..

Login to post response

Comment using Facebook(Author doesn't get notification)