星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DataProvider.cs 1.8KB

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