SHA1 ,MD5 加密 using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; namespace Qifan.Common { /**//// <summary> /// 加密/解密字符串 /// </summary> public class Security { /**//// <summary> /// MD5 加密 /// </summary> /// <param name="passWord">需要加密的字符串</param> /// <returns>加密后的字符串</returns> public static string Md5(string passWord) { Byte[] clearBytes = new UnicodeEncoding().GetBytes(passWord); Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); return BitConverter.ToString(hashedBytes); } /**//// <summary> /// SHA1 加密 /// </summary> /// <param name="passWord">需要加密的字符串</param> /// <returns>加密后的字符串</returns> public static string Sha1(string passWord) { Byte[] clearBytes = new UnicodeEncoding().GetBytes(passWord); Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("SHA1")).ComputeHash(clearBytes); return BitConverter.ToString(hashedBytes); } } }