| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /**
- *
- * @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";
- /// <summary>
- /// DES加密
- /// </summary>
- /// <param name="sourceString">The source string.</param>
- /// <returns>System.String.</returns>
- 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;
- }
- }
- /// <summary>
- /// DES解密
- /// </summary>
- /// <param name="encryptedString">The encrypted string.</param>
- /// <returns>System.String.</returns>
- 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;
- }
- }
- }
- }
|