CopyCode The Code is as follows: /*************************************** ***********
* Copyright: mr_sheng
* File name: encrypthelper. CS
* File description:
* Type description: encrypthelper encryption help class
* Authorization statement:
* Book Program For free software;
* You may re-publish and/or modify this program in accordance with the GPL V3 authorization Terms issued by the Free Software Foundation;
* This procedure is released for the purpose of use, but is not subject to any Warranty liability;
* There is also no implied guarantee for the suitability of sales or specific purposes.
* For details, see GNU General Public Authorization v3(see the license.txt file ).
* Version history:
* V2.0.0 mr_sheng Modification
*
**************************************** ***********/
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Security. cryptography;
Namespace Sheng. Common
{
/// <Summary>
/// Encryption help class
/// </Summary>
Public class encrypthelper
{
/// <Summary>
/// MD5 Encryption
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Public static string md5decryptstring (string Str)
{
Md5cryptoserviceprovider MD5 = new md5cryptoserviceprovider ();
Byte [] md5source = system. Text. encoding. utf8.getbytes (STR );
Byte [] md5out = md5.computehash (md5source );
Return convert. tobase64string (md5out );
}
///
// DES encrypted string
///
/// input character
/// key
/// encrypt the result
Public String desencryptstring (string sinputstring, string skey)
{< br> try
{< br> byte [] DATA = encoding. default. getbytes (sinputstring);
byte [] result;
descryptoserviceprovider des = new descryptoserviceprovider ();
des. key = asciiencoding. ASCII. getbytes (skey); // key
des. IV = asciiencoding. ASCII. getbytes (skey); // initialization vector
icryptotransform desencrypt = des. createencryptor (); // encryptor object
result = desencrypt. transformfinalblock (data, 0, Data. length); // convert the specified region of the specified byte array
return bitconverter. tostring (result);
}< br> catch (exception ex)
{< br> // ex. message = "DES encryption exception";
throw ex;
}< BR >}
///
// des decryption string
///
/// enter the character
/// key
/// decrypt the result
Public String desdecryptstring (string sinputstring, string skey)
{< br> try
{< br> // convert a string to a byte array
string [] sinput = sinputstring. split ("-". tochararray ();
byte [] DATA = new byte [sinput. length];
byte [] result;
for (INT I = 0; I {< br> data [I] = byte. parse (sinput [I], system. globalization. numberstyles. hexnumber);
}
descryptoserviceprovider des = new descryptoserviceprovider ();
des. key = asciiencoding. ASCII. getbytes (skey);
des. IV = asciiencoding. ASCII. getbytes (skey);
icryptotransform desencrypt = des. createdecryptor ();
result = desencrypt. transformfinalblock (data, 0, Data. length);
return encoding. default. getstring (result);
}< br> catch (exception ex)
{< br> // ex. message = "des decryption exception";
throw ex;
}< BR >}