Encryption is required for the current web system.
Select MD5 as usual (in fact, I have used MD5 ^_^)
Two implementations are found.
/**////
/// Use MD5 Encryption
///
/// Input data
///
Public static string MD5 (string sourcein)
...{
Md5cryptoserviceprovider md5csp = new md5cryptoserviceprovider ();
Byte [] md5source = system. Text. encoding. utf8.getbytes (sourcein );
Byte [] md5out = md5csp. computehash (md5source );
Return convert. tobase64string (md5out );
}
Public static string MD5 (string STR, int code)
...{
If (code = 16) // 16-bit MD5 encryption (take 32-bit encryption 9 ~ 25 characters)
...{
Return System. Web. Security. formsauthentication. hashpasswordforstoringinconfigfile (STR, "MD5"). tolower (). substring (8, 16 );
}
If (code = 32) // 32-bit encryption
...{
Return System. Web. Security. formsauthentication. hashpasswordforstoringinconfigfile (STR, "MD5"). tolower ();
}
Return "00000000000000000000000000000000 ";
}
There are two methods. The first method is to encrypt the byte data through the md5cryptoserviceprovider class.
The second type of direct encryption uses the string type as the parameter, which is more intuitive.
What is the result of two encryption statements ??
Textbox1.text = md51 ("12345 ");
Textbox2.text = md52 ("12345", 32 );
Md51: gnzlduqkcgxmnkfokfhoew =
Md52: 827ccb0eea8a706c4c34a16891f84e7b
Why? Different. I use my intuition to judge that the second is the MD5 encryption I often see.
The first method is hard to understand.
Tip
The second method is to use. tolower () to be compatible with MD5 encryption in ASP;
Compatibility with ASP and encryption of Chinese characters may cause Encoding Problems.