I'M .NET

.NET 技术
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

兼容动网ASP版本的MD5算法

Posted on 2008-12-15 10:38  宝猪  阅读(159)  评论(0)    收藏  举报

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace Utility
{
    
public class Util
    {

        
public static string MD5Hash(string str)
        {
            
byte[] generatedHash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
            StringBuilder sb 
= new StringBuilder();
            
for (int i = 0; i < 16; i++)
            {
                sb.Append(generatedHash[i].ToString(
"x2"));
            }
            
return sb.ToString();
        }
    }
}