加龙

加龙加香不加价
随笔 - 133, 评论 - 336 , 引用 - 51

.NET MD5 加密代码 (C#)

在网页制作中经常回使用MD5加密一些 密码 或一些 字符串.一下就是一段MD5的加密代码.

using System;
using System.Security.Cryptography;
namespace ArLi.CommonPrj
{
    public class getMD5
    {
        public getMD5()
        {

        }
        /// 返回 MD5 值
        /// 要转换的 MD5 值的字符串
        public string getOf(string myString) {
            MD5 md5  = new MD5CryptoServiceProvider();
            byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString);
            byte[] targetData = md5.ComputeHash(fromData);
            string byte2String = null;
            for (int i=0; i"x");
            }
            return byte2String;
        }
        /// 返回 MD5 值
        /// 要转换的 MD5 值的字符串
        /// 分隔符
        public string getOf(string myString,string splitChar) {
            MD5 md5  = new MD5CryptoServiceProvider();
            byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString);
            byte[] targetData = md5.ComputeHash(fromData);
            string byte2String = null;
            for (int i=0; i"x") + splitChar;
            }
            if (splitChar != null && splitChar != ""){
                return byte2String.Remove(byte2String.Length -1,1);
            }
            return byte2String;
        }
        /// 返回 MD5 值
        /// 要转换的 MD5 值的字符串
        /// 分隔符
        public string getOf(string myString,char splitChar) {
            MD5 md5  = new MD5CryptoServiceProvider();
            byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString);
            byte[] targetData = md5.ComputeHash(fromData);
            string byte2String = null;
            for (int i=0; i"x") + splitChar;
            }
            return byte2String.Remove(byte2String.Length -1,1);
        }
    }
}

发表于 2006年6月6日 12:47

评论

# re: .NET MD5 加密代码 (C#)

/// <summary>
/// MD5 加密函数
/// </summary>
/// <param name="str"></param>
/// <param name="code"></param>
/// <returns></returns>
public static string MD5(string str,int code)
{

if(code==16)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower().Substring(8,16) ;
}

if(code==32)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5");
}

return "00000000000000000000000000000000";
}
2006-6-6 12:49 | ddf3

# re: .NET MD5 加密代码 (C#)

不错,收藏
2007-2-3 23:58 | 注册香港公司

Post Comment

主题  
姓名  
主页
校验码  
内容   
京ICP备 05050892号