加密

 

使用System.Web.Security命名空间对ASP.NET中字符加密
2007-09-28 15:16

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

 

public partial class _5_09 : System.Web.UI.Page
{
      protected void Page_Load(object sender, EventArgs e)
      {
          string s1 = "We are happy!";
          Response.Write("字符串"+s1+"经过sha1加密后为:<br>");
          string s2 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s1, "sha1");
          Response.Write(s2);
          Response.Write("<br>");
          string s3 = "goodluck";
          Response.Write("字符串"+s3+"经过md5加密后为:<br>");
          string s4 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s1, "md5");
          Response.Write(s4);
          Response.Write("<br>");

      }
}
结果为:

字符串We are happy!经过sha1加密后为:
CBAFFA21FEAE5252B4E9041581D3080B7D4AFAF5
字符串goodluck经过md5加密后为:
D6C4AD84708D89951BDD8E8C609C0F69

 

 

//

using System.Security.Cryptography;
using System.Text;

public static string MD5(string source)
    {
        byte[] data = Encoding.Unicode.GetBytes(source.ToCharArray());
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(data);
        string sResult = Encoding.Unicode.GetString(result);
        return sResult;
    }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值