/** * * @date 2014-11-01 * * @author 邓尹平 * * @par 成员列表类 说明 * 主要负责管理成员 提供搜索\排序和操作的方法 * * @par 版权声明 * 深圳市多元世纪信息技术有限公司 版权所有 * * @see 使用此类时参照一些其他类可以写在这里 * * @todo 该类有待完成的任务 一条条列出 完成一条删除一条 * * @bug 该类已知的Bug一条条列出 完成一条删除一条 * */ using System; using System.Globalization; using System.Security.Cryptography; using System.Text; namespace Muchinfo.PC.Common.Helpers { public class DESHelper { private static readonly string _key = "MuChInFo"; /// /// DES加密 /// /// The source string. /// System.String. public static string Encrypt(string sourceString) { try { byte[] data = Encoding.UTF8.GetBytes(sourceString); var des = new DESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(_key), IV = Encoding.ASCII.GetBytes(_key) }; ICryptoTransform desencrypt = des.CreateEncryptor(); byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length); return BitConverter.ToString(result); } catch (Exception e) { throw e; } } /// /// DES解密 /// /// The encrypted string. /// System.String. public static string Decrypt(string encryptedString) { try { string[] sInput = encryptedString.Split("-".ToCharArray()); byte[] data = new byte[sInput.Length]; for (int i = 0; i < sInput.Length; i++) { data[i] = byte.Parse(sInput[i], NumberStyles.HexNumber); } var DES = new DESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(_key), IV = Encoding.ASCII.GetBytes(_key) }; ICryptoTransform desencrypt = DES.CreateDecryptor(); byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length); return Encoding.UTF8.GetString(result); } catch (Exception e) { throw e; } } } }