

Navigator : Home > Tutorials > Advanced Technologies Tutorials > ...
Secret by MD5 using ASP.NET 2.0 and C#.NET
This example demonstrates how to use MD5 add secret using Asp.Net2.0 and C#.Net
This example demonstrates how to use MD5 add secret.
First, you will need to import the System.Collections.Cryptography and System.Collections.Text namespace.
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.
using System.Security.Cryptography; using System.Text; |
The System.Security.Cryptography namespace provides cryptographic services, including secure encoding and decoding of data, as well as many other operations, such as hashing, random number generation, and message authentication.
The System.Text namespace contains classes representing ASCII, Unicode, UTF-7, and UTF-8 character encodings; abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats string objects without creating intermediate instances of String.
We use the Md5AddSecret Function to do the work.
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
public string Md5AddSecret(string strChange) {
byte[] pass = Encoding.UTF8.GetBytes(strChange); MD5 md5 = new MD5CryptoServiceProvider(); string strPassword = Encoding.UTF8.GetString(md5.ComputeHash(pass)); return strPassword; } |
The front end Md5AddSecretCsharp2005.aspx page looks something like this:
<table border="1"style="width: 323px; height: 76px;">
<tr>
<td style="width: 190px; height: 28px;"> Need To Add Secret :</td> <td style="width: 91px; height: 28px;"> <asp:TextBox ID="txtNeed" runat="server" Width="128px"></asp:TextBox></td> </tr> <tr>
<td style="width: 190px"> Encrypt Result :</td> <td style="width: 91px"> <asp:TextBox ID="TxtResult" runat="server" Height="17px" Width="130px" ReadOnly="True"></asp:TextBox></td> </tr> <tr>
<td colspan="2" style="height: 26px"> <asp:Button ID="bntDisp" runat="server" OnClick="bntDisp_Click" Text="Add secret" /></td> </tr> </table> |
The flow for the code behind page is as follows.
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Security.Cryptography; using System.Text;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { } public string Md5AddSecret(string strChange) {
//Change the syllable into UTF8 code byte[] pass = Encoding.UTF8.GetBytes(strChange);
MD5 md5 = new MD5CryptoServiceProvider(); string strPassword = Encoding.UTF8.GetString(md5.ComputeHash(pass)); return strPassword; } protected void bntDisp_Click(object sender, EventArgs e) {
try {
this.TxtResult.Text = this.Md5AddSecret(this.txtNeed.Text); } catch (Exception ex) {
Response.Write(ex.ToString()); } } } |
We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!