Copy Code code as follows:
/**************************************************
* All rights reserved: Mr_sheng
* FileName: EncryptHelper.cs
* File Description:
* Type description: Encrypthelper encryption Help Class
* Authorization statement:
* This procedure is free software;
* You may redistribute and/or modify this procedure in accordance with the GPL V3 license Terms issued by the Free Software Foundation;
* This procedure is issued for the purpose of use, but does not bear any liability for security;
* There is no implied warranty of merchantability or fitness for a particular purpose.
* For details please refer to the GNU General Public License V3 (see License.txt file).
* Version history:
* v2.0.0 Mr_sheng 2009-09-09 Revision
*
***************************************************/
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);
}
<summary>
Des encrypted string
</summary>
<param name= "sinputstring" > Input character </param>
<param name= "SKey" >Key</param>
<returns> Encryption Results </returns>
public string desencryptstring (string sinputstring, String SKey)
{
Try
{
byte[] data = Encoding.Default.GetBytes (sinputstring);
Byte[] result;
DESCryptoServiceProvider DES = new DESCryptoServiceProvider ();
Des. Key = ASCIIEncoding.ASCII.GetBytes (SKey); Secret key
DES.IV = ASCIIEncoding.ASCII.GetBytes (SKey); Initializing vectors
ICryptoTransform desencrypt = DES. CreateEncryptor (); Cryptographic object
result = Desencrypt. TransformFinalBlock (data, 0, data.) Length); Converts a specified range of specified byte arrays
return bitconverter.tostring (Result);
}
catch (Exception ex)
{
Ex. Message = "DES encryption exception";
Throw ex;
}
}
<summary>
Des decryption string
</summary>
<param name= "sinputstring" > Input character </param>
<param name= "SKey" >Key</param>
<returns> Decryption Results </returns>
public string desdecryptstring (string sinputstring, String SKey)
{
Try
{
Converts a string to a byte array
string[] Sinput = Sinputstring.split ("-"). ToCharArray ());
byte[] data = new Byte[sinput.length];
Byte[] result;
for (int i = 0; i < sinput.length; i++)
{
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);
}
catch (Exception ex)
{
Ex. Message = "Des decryption exception";
Throw ex;
}
}
}
}