星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Common.system
  9. {
  10. public class DataProvider
  11. {
  12. ///3DES解密
  13. public static string TripleDESDecrypt(string pToDecrypt, string sKey)
  14. {
  15. sKey = sKey.Substring(0, 24);
  16. TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider
  17. {
  18. Mode = CipherMode.ECB,
  19. Padding = PaddingMode.Zeros
  20. };
  21. byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
  22. for (int x = 0; x < pToDecrypt.Length / 2; x++)
  23. {
  24. int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
  25. inputByteArray[x] = (byte)i;
  26. }
  27. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  28. des.IV = new byte[] { 0, 00, 00, 00, 00, 00, 00, 00, };
  29. MemoryStream ms = new MemoryStream();
  30. CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
  31. cs.Write(inputByteArray, 0, inputByteArray.Length);
  32. cs.FlushFinalBlock();
  33. StringBuilder ret = new StringBuilder();
  34. return System.Text.Encoding.Default.GetString(ms.ToArray()).Replace("\0", "");
  35. }
  36. /// <summary>
  37. /// 返回一个时间戳到秒
  38. /// </summary>
  39. /// <returns></returns>
  40. public static long TimestampTotalSeconds()
  41. {
  42. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  43. long timestr = Convert.ToInt64(ts.TotalSeconds);
  44. return timestr;
  45. }
  46. }
  47. }