|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
-
- namespace Common.system
- {
- public class DataProvider
- {
- ///3DES解密
- public static string TripleDESDecrypt(string pToDecrypt, string sKey)
- {
- sKey = sKey.Substring(0, 24);
- TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider
- {
- Mode = CipherMode.ECB,
- Padding = PaddingMode.Zeros
- };
- byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
- for (int x = 0; x < pToDecrypt.Length / 2; x++)
- {
- int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
- inputByteArray[x] = (byte)i;
- }
-
- des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
- des.IV = new byte[] { 0, 00, 00, 00, 00, 00, 00, 00, };
- MemoryStream ms = new MemoryStream();
- CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
- cs.Write(inputByteArray, 0, inputByteArray.Length);
- cs.FlushFinalBlock();
-
- StringBuilder ret = new StringBuilder();
-
- return System.Text.Encoding.Default.GetString(ms.ToArray()).Replace("\0", "");
- }
- /// <summary>
- /// 返回一个时间戳到秒
- /// </summary>
- /// <returns></returns>
- public static long TimestampTotalSeconds()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- long timestr = Convert.ToInt64(ts.TotalSeconds);
- return timestr;
- }
- }
- }
|