using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; 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", ""); } /// /// 返回一个时间戳到秒 /// /// 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; } } }