OldHawk

菜地一块,欢迎拍砖
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MD5 Library in .NET

Posted on 2007-04-30 12:23  OldHawk  阅读(331)  评论(0编辑  收藏  举报

      我写的一个.net里面用于md5加密的类。

using System;
using System.Security.Cryptography;

namespace md5
{
    
/// <summary>
    
/// Class1 的摘要说明。
    
/// </summary>
    public class stringToMD5
    {
        
public stringToMD5()
        {
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

        
public static string makeMD5(string source)
        {
            
byte[] b=System.Text.Encoding.Default.GetBytes(source);
            b
=new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
            
string ret="";
            
for(int i=0;i<b.Length;i++)
                ret
+=b[i].ToString ("x").PadLeft(2,'0');
            
return ret;
        }
    }
}