kongxx's blog

有困难要上,没有困难创造困难也要上!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#的MD5实现

Posted on 2005-09-30 16:28  kongxx  阅读(1145)  评论(0编辑  收藏  举报
 1        public String md5(String s) 
 2        {
 3            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();            
 4            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
 5            bytes = md5.ComputeHash(bytes);
 6            md5.Clear();
 7
 8            string ret = "";
 9            for(int i=0 ; i<bytes.Length ; i++)
10            {                
11                ret += Convert.ToString(bytes[i],16).PadLeft(2,'0');
12            }

13  
14            return ret.PadLeft(32,'0');
15        }