/**************************************************
* Copyright: Mr_Sheng
* file name:
* File description:
* Type Description: EncryptHelper encryption help class
* Authorization Statement:
* This program is free software;
* You may re-publish and/or modify this program in accordance with the GPL v3 authorization terms published by the Free Software Foundation;
* This program is published for the purpose of use, but it is not subject to any warranty;
* No implied warranty of suitability for sale or fitness for a particular purpose.
* Please refer to GNU General Public Authorization v3 (see document) for details.
* Version History:
* v2.0.0 Mr_Sheng 2009-09-09 Modified
*
***************************************************/
using System;
using ;
using ;
using ;
namespace
{
/// <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 = .(str);
byte[] md5Out = (md5Source);
return Convert.ToBase64String(md5Out);
}
/// <summary>
/// DES encryption 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 = (sInputString);
byte[] result;
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
= (sKey); //Key
= (sKey); //Initialize vector
ICryptoTransform desencrypt = (); //Encryptor object
result = (data, 0, ); //Convert the specified area of the specified byte array
return (result);
}
catch (Exception ex)
{
// = "DES encryption exception";
throw ex;
}
}
/// <summary>
/// DES decryption string
/// </summary>
/// <param name="sInputString">Input Character</param>
/// <param name="sKey">Key</param>
/// <returns>Decrypt results</returns>
public string DESDecryptString(string sInputString, string sKey)
{
try
{
//Convert string to byte array
string[] sInput = ("-".ToCharArray());
byte[] data = new byte[];
byte[] result;
for (int i = 0; i < ; i++)
{
data[i] = (sInput[i], );
}
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
= (sKey);
= (sKey);
ICryptoTransform desencrypt = ();
result = (data, 0, );
return (result);
}
catch (Exception ex)
{
// = "DES decryption exception";
throw ex;
}
}
}
}