Happy Pig's - 哼哼
开开心心每一天,勤勤奋奋过日子。
     Md5Encode 算法的目标是要得到一个文件的32位十六进制表示的MD5值,.net提供的计算MD5值的类是位于System.Security.Cryptography命名空间下的MD5CryptoServiceProvider类

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

namespace MD5_MethodTest
{
    class MD5Encode
    {
        private string Encode(string InitString)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] btSerialCode;
            btSerialCode = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(InitString));
            string EncryptedString =BitConverter.ToString(btSerialCode).Replace("-", "");
            return EncryptedString;
        }
    }
}

 

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

namespace Suzsoft.MMS.Common
{

    public class Md5Encode
    {
        public static string Encode(string strOriginal)
        {
            MD5CryptoServiceProvider objMD5 = new MD5CryptoServiceProvider();

            byte[] byteInput = UTF8Encoding.UTF8.GetBytes(strOriginal);         
            byte[] byteOutput = objMD5.ComputeHash(byteInput);
            return BitConverter.ToString(byteOutput).Replace("-","");
        }
    }
}

posted on 2008-03-31 14:26  boulder  阅读(2417)  评论(0编辑  收藏  举报