MD5加密

public partial class Default3 : System.Web.UI.Page
{   ///MD5加密的实例
    protected void Page_Load(object sender, EventArgs e)
    {
        //将要加密的字符串转化为byte类型
        byte[] data = System.Text.Encoding.Unicode.GetBytes(txtUid.Text.ToCharArray());
        //创建一个Md5对象
        System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        //加密Byte[]数组
        byte[] result = md5.ComputeHash(data);
        //将加密后的数组转化为字段
        string sResult = System.Text.Encoding.Unicode.GetString(result);
        //打印普通加密后的结果
        show1.Text = "MD5普通加密:" + sResult.ToString() + "<br/>";
        //打印密码方式加密
        string EnPswdStr = System.Web.Security.FormsAuthentication.
        HashPasswordForStoringInConfigFile(txtUid.Text.ToString(), "MD5");
        //显示出来
        show2.Text = "MD5密码加密:" + EnPswdStr + "<br/>";
    }
}

 

posted @ 2015-03-24 08:56  清幽紫竹  Views(107)  Comments(0)    收藏  举报