Before this encryption help class feel not rigorous enough, not strong enough, so deliberately modified, also responsible for their own a little, if you have help can see,///hehe! ~ This class has been tested by me is not a problem. Using system;using system.collections.generic;using system.io;using system.linq;using System.runtime.serialization.formatters.binary;using system.security.cryptography;using System.Text;using log4net ; namespace utility{//<summary>//@Author: Liang Jilong//@Date: 2012/7/30//@Descripte: Encrypthelper Encryption helper class. </summary> public class Encrypthelper {///<summary>//Method One:///The string after this type of encryption is 32-bit (alpha plus data) string///Example:password is admin encryption becomes post 21232F297A57A5A743894A0E4A801FC3//</summary> <param name= "Beforestr" ></param>///<returns></returns> public string Md5en Crypt (String beforestr) {string afterstring = ""; try {MD5 MD5 = MD5. Create (); byte[] Hashs = Md5.computehash (Encoding.UTF8.GetBytes (BEFORESTR)); FoReach (byte by in HASHS)//Here is the letter plus data to encrypt.//3y can, y3 can not or x3j etc should be more than 32 bits not afterstring + = by. ToString ("X2"); } catch (Exception ex) {ILog log = log4net. Logmanager.getlogger (this. GetType ()); Log. Error ("============== you have caused a mistake to be ==============" + ex. Message.tostring ()); } return afterstring; }///<summary>///Method two//HashAlgorithm encryption//This encryption is a letter plus-plus character///EXAMPLE:PA ssWOrd is admin encryption becomes after 19-a2-85-41-44-b6-3a-8f-76-17-a6-f2-25-01-9b-12//</summary>//<param name= "p Assword "></param>///<returns></returns> public string Hashencrypt (string password) {byte[] hashedbytes = null; try {byte[] clearbytes = new UnicodeEncoding (). GetBytes (password); Hashedbytes = ((HashAlgorithm) Cryptoconfig.createfromName ("MD5")). ComputeHash (clearbytes); } catch (Exception ex) {ILog log = log4net. Logmanager.getlogger (this. GetType ()); Log. Error ("============== you have caused a mistake to be ==============" + ex. Message.tostring ()); } return Bitconverter.tostring (hashedbytes);//MD5 encryption}//<summary>///Method Three: MD5 + hashcode Encryption///Example:password is admin encryption becomes after 895b7da64943134be17b825ce118456c//</summary >//<returns></returns> public string Md5hashcodeencrypt (string encryptpwd) { Return Md5encrypt (Hashencrypt (encryptpwd)); On the basis of Hashencrypt MD5}//<summary>//////Hashcode +MD5 encryption///Example: Password is admin encryption becomes after eb-1d-6d-e2-fc-f1-cd-94-4d-75-78-e6-3d-7a-12-32//</summary>//<param name = "Encryptpwd" ></param>//<returns></returns&Gt public string Hashcodemd5encrypt (string encryptpwd) {return Hashencrypt (Md5encrypt (ENCRYPTPWD));//In MD5 Basic RE Hashcode}///<summary>//Method five//</summary>//<param name= "Encr Yptpwd "></param>///<returns></returns> public string Hashmd5encrypt (string ENCRYPTPW d) {return Hashcodemd5encrypt (Hashcodemd5encrypt (ENCRYPTPWD));//Hashcodemd5encrypt basis and Hashcode }///<summary>///six///haha isn't it a bit dizzy? Big guy can keep writing. </summary>//<param name= "encryptpwd" ></param>//<returns></returns> public string Md5hashencrypt (string encryptpwd) {return Md5hashcodeencrypt (Md5hashcodeencrypt (ENC RYPTPWD)); On MD5 basis hashcode}///<summary>//64-bit double MD5 lowercase//</summary>//<ret Urns></returns> public static string Last64 (string s) {if (s.length! =) return ""; string S1 = s.substring (0, 16); String s2 = s.substring (16, 16); Return Lower32 (S1) + Lower32 (S2); }//<summary>//32 caps///</summary>//<returns></returns> public static string Upper32 (string s) {s = System.Web.Security.FormsAuthentication.HashPasswordForSt Oringinconfigfile (S, "MD5"). ToString (); return S.toupper (); }//<summary>//32-bit lowercase//</summary>//<returns></returns> public static string Lower32 (string s) {s = System.Web.Security.FormsAuthentication.HashPasswordForSt Oringinconfigfile (S, "MD5"). ToString (); return S.tolower (); }///<summary>//16 caps///</summary>//<returns></returns> public static string Upper16 (string s) {s = System.Web.Security.FormsAuthentication.HashPa Sswordforstoringinconfigfile (S, "MD5"). ToString (); Return S.toupper (). Substring (8, 16); }//<summary>//16-bit lowercase//</summary>//<returns></returns> public static string Lower16 (string s) {s = System.Web.Security.FormsAuthentication.HashPasswordForSt Oringinconfigfile (S, "MD5"). ToString (); Return S.tolower (). Substring (8, 16); } } }
Encrypthelper Encryption Helper Class