using System;using System.Text;using System.Security.Cryptography; namespace MD5{ public class MD5 { // 32 位 public static String Encrypt(String s) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s); bytes = md5.ComputeHash(bytes); md5.Clear(); string ret = ""; for (int i = 0; i < bytes.Length; i++) { ret += Convert.ToString(bytes[i], 16).PadLeft(2, ‘0‘); } return ret.PadLeft(32, ‘0‘); } // 16 位 public static string Encrypt16(string ConvertString) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8); t2 = t2.Replace("-", ""); return t2; } }} -------------------------------------引用MD5命名空间using MD5;直接用MD5.Encrypt(textbox1.Text);即可加密;MD5没有解密的算法,要不然就不用加密了,网上有一些解密的网站,有些能解密,有些解密不了,有些还需要收费才能解密。
时间: 2024-11-06 03:16:02