- UsingSystem;
- UsingSystem. Data;
- UsingSystem. Configuration;
- UsingSystem. Collections;
- UsingSystem. Web;
- UsingSystem. Web. Security;
- UsingSystem. Web. UI;
- UsingSystem. Web. UI. WebControls;
- UsingSystem. Web. UI. WebControls. WebParts;
- UsingSystem. Web. UI. HtmlControls;
- UsingOA online. BLL;
- UsingSystem. Diagnostics;
- UsingSystem. Text;
- UsingSystem. Security. Cryptography;
- UsingSystem. IO;
- // 1. encrypted to a 32-bit hexadecimal string
- Protected StringHashMD5_String (StringStr)
- {
- ReturnFormsAuthentication. HashPasswordForStoringInConfigFile (str, "MD5"). ToLower ();
- }
- // 2. Same as above, increase the offset
- Public StringGetMD5 (StringSDataIn,StringMove)
- {
- System. Security. Cryptography. MD5CryptoServiceProvider md5 =NewSystem. Security. Cryptography. MD5CryptoServiceProvider ();
- Byte[] Byt, bytHash;
- Byt = System. Text. Encoding. UTF8.GetBytes (move + sDataIn );
- BytHash = md5.ComputeHash (byt );
- Md5.Clear ();
- StringSTemp = "";
- For(IntI = 0; I <bytHash. Length; I ++)
- {
- STemp + = bytHash [I]. ToString ("x"). PadLeft (2, '0 ');
- }
- ReturnSTemp;
- }
- // 3. encode the string into an ASCII array and then encrypt it with MD5.
Using System; using System. data; using System. configuration; using System. collections; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; using OAOnline. BLL; using System. diagnostics; using System. text; using System. security. cryptography; using System. IO; // 1. encrypted to a 32-bit hexadecimal string protected string HashMD5_String (string str) {return FormsAuthentication. hashPasswordForStoringInConfigFile (str, "MD5 "). toLower ();} // 2. Same as above, add the offset public string GetMD5 (string sDataIn, string move) {System. security. cryptography. MD5CryptoServiceProvider md5 = new System. security. cryptography. MD5CryptoServiceProvider (); byte [] byt, bytHash; byt = System. text. encoding. UTF8.GetBytes (move + sDataIn); bytHash = md5.ComputeHash (byt); md5.Clear (); string sTemp = ""; for (int I = 0; I <bytHash. length; I ++) {sTemp + = bytHash [I]. toString ("x "). padLeft (2, '0');} return sTemp;} // 3. encode the string into an ASCII array and then encrypt it with MD5.
C # code
- Public static string MD5Encrypt (string strEnc)
- {
- String str = "encryption failed! ";
- Try
- {
- System. Security. Cryptography. MD5CryptoServiceProvider MD5 = new System. Security. Cryptography. MD5CryptoServiceProvider ();
- Str = ASCIIEncoding. ASCII. GetString (MD5.ComputeHash (ASCIIEncoding. ASCII. GetBytes (strEnc )));
- Return str;
- }
- Catch (System. Exception ex)
- {
- Throw (ex );
- }
- }