ASP.NET-------MD5加密设计

简单的对文本进行Md5加密小工具效果如下:

ASP.NET-------MD5加密设计

App code中添加Md5Help类:

  
    
public static class MD5Helper
{
public static string MD5Hash( this string s) // 扩展方法
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s, " md5 " );
}

private static string str;
public static string MD5Str
{
get
{
return str.MD5Hash(); // 调用扩展方法
}
set {str = value;}
}
}

Md5.cs代码:

  
    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MD5
{
public partial class Md5 : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{

}

protected void btnMD5_Click( object sender, EventArgs e)
{
MD5Helper.MD5Str
= this .txtText.Text;
this .lblResult.Text = MD5Helper.MD5Str;
}
}
}

前台布局:

  
    
< body >
< form id ="form1" runat ="server" >
< div style ="text-align:center" >
MD5加密文本
< asp:TextBox runat ="server" ID ="txtText" ></ asp:TextBox >
< asp:Button runat ="server" ID ="btnMD5" Text ="加密" onclick ="btnMD5_Click" />
< br />
加密后文本:
< asp:Label runat ="server" ID ="lblResult" ></ asp:Label >
</ div >
</ form >
</ body >

你可能感兴趣的:(asp.net)