【笔记】MD5加密
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace CTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*******MD5加密工具*********");
while (true)
{
Console.Write("输入字符串:");
byte[] content;
content = Encoding.Default.GetBytes(Console.ReadLine().Trim()); //去除首尾空格
MD5 md5 = new MD5CryptoServiceProvider(); //实例化MD5对象
byte[] result32 = md5.ComputeHash(content); //计算hash
string output32 = BitConverter.ToString(result32).Replace("-", ""); //算出来的hash两位一个“-”分隔
string output16 = output32.Substring(8, 16); //16位的为32位密文的8-24位
Console.WriteLine("MD5-16位加密后为:{0}", output16);
Console.WriteLine("MD5-32位加密后为:{0}", output32);
Console.WriteLine();
}
}
}
}
笔记之用,记录一下