C# 加密方法MD5 Encryption Implement MD5

MD5的简单的例子

using System.Security.Cryptography;
using System.Text;
static public void Main()
    {
        string line, ret;
        while (true)
        {
            line = Console.ReadLine();
            byte[] result = Encoding.Default.GetBytes(line.Trim());    //tbPass为输入密码的文本框
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            ret = BitConverter.ToString(output).Replace("-", "");
            Console.WriteLine(ret);
            Console.WriteLine("length: {0:D2}", ret.Length);
        }
    }
每次生成的MD5码长度都是32,由于MD5码不可逆,所以可以用于数据库存储,数据类型可以为VARCHAR(20)或者是TCHAR(20)。
 
 
原文地址:https://www.cnblogs.com/rogerroddick/p/2981255.html