一、md5加密解密
1、加密
C# 代码 复制public static string ToMd5(string clearString) { Byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearString); string hashedPwd = BitConverter.ToString(((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes)); return hashedPwd; }
2、32位MD5加密
C# 代码 复制public static string GetMd5Base32(string sInput) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); System.Security.Cryptography.MD5 md5; byte[] bytesSrc; byte[] result; StringBuilder sb = new StringBuilder(); bytesSrc = encoding.GetBytes(sInput); md5 = new System.Security.Cryptography.MD5CryptoServicePRovider(); result = md5.ComputeHash(bytesSrc); for (int i = 0; i < result.Length; i++) { sb.AppendFormat("{0:x2}", result[i]); } return sb.ToString(); }
二、DES加密解密
1、加密
C# 代码 复制DESEncrypt DES加密
2、解密
C# 代码 复制DESDecrypt DES解密
三、base64算法加密解密
C# 代码 复制/// <summary> /// 有关base64编码算法的相关操作 /// </summary> public class Base64 { public Base64() { } /// <summary> /// 将字符串使用base64算法加密 /// </summary> /// <param name="sourceString">待加密的字符串</param> /// <param name="ens">System.Text.Encoding 对象,如创建中文编码集对象:System.Text.Encoding.GetEncoding(54936)</param> /// <returns>加码后的文本字符串</returns> public static string EncodingForString(string sourceString, System.Text.Encoding ens) { return Convert.ToBase64String(ens.GetBytes(sourceString)); } /// <summary> /// 将字符串使用base64算法加密 /// </summary> /// <param name="sourceString">待加密的字符串</param> /// <returns>加码后的文本字符串</returns> public static string EncodingForString(string sourceString) { return EncodingForString(sourceString, System.Text.Encoding.GetEnc
新闻热点
疑难解答