天天@BLOG

脖子越来越疼,脑袋越来越钝
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MD5加密算法

Posted on 2006-01-04 09:34  天天在线  阅读(205)  评论(0)    收藏  举报

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

/// <summary>
/// MD5加密
/// </summary>
/// <param name="sDataIn"></param>
/// <returns></returns>
public string GetMD5(string sDataIn)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5=new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[]bytValue,bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp="";
for(int i=0;i<bytHash.Length;i++)
{
sTemp+=bytHash[i].ToString("X").PadLeft(2,'0');
}
return sTemp.ToUpper();
}

@忙碌,不代表有效率;方法,远胜于苦干