MD5是经典HASH算法,这里用C#实现一边:
using System;
using System.Security.Cryptography;
using System.Text;
namespace ConsoleApp1
{
class Program
{
// 32位md5加密
public static string GetMD5_32(string s, string _input_charset)
{
MD5 md5 = MD5.Create();
byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(s));
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < t.Length; i++)
{
stringBuilder.Append(t[i].ToString("x").PadLeft(2, '0'));
}
return stringBuilder.ToString();
}
// 16位md5加密
public static string GetMD5_16(string s)
{
MD5 md5 = MD5.Create();
byte[] t = md5.ComputeHash(UTF8Encoding.Default.GetBytes(s));
string t2 = BitConverter.ToString(t, 4, 8);
t2 = t2.Replace("-", "");
return t2;
}
static void Main(string[] args)
{
Console.WriteLine(GetMD5_32("123456", "utf-8"));
Console.WriteLine(GetMD5_16("123456"));
Console.ReadLine();
}
}
}