MD5生成函数

来源:互联网 发布:泰语中文翻译软件 编辑:程序博客网 时间:2024/06/06 06:55

souce: if you know, please tell me. thanks!

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;

 

         /// <summary>
        /// function to generate MD5
        /// </summary>
        /// <param name="inStr"></param>
        /// <returns></returns>

        private string calculatemd5(string inStr)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] InBytes = Encoding.GetEncoding("GB2312").GetBytes(inStr);
            byte[] OutBytes = md5.ComputeHash(InBytes);
            string OutString = "";
            for (int i = 0; i < OutBytes.Length; i++)
            {
                OutString += OutBytes[i].ToString("x2");
            }
            return OutString;
        }