123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Security.Cryptography;
- using System.Text;
-
- namespace Common.system
- {
- public class DataProvider
- {
-
- 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;
- }
-
-
-
-
-
-
-
- public static string SerializeDictionaryToJsonString<TKey, TValue>(Dictionary<TKey, TValue> dict)
- {
- if (dict.Count == 0)
- {
- return "";
- }
-
- string jsonStr = JsonConvert.SerializeObject(dict);
- return jsonStr;
- }
-
-
-
-
-
- public static string HttpPost(string body, string Url)
- {
- try
- {
- Encoding encoding = Encoding.UTF8;
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- request.Method = "POST";
- request.Accept = "text/html,application/xhtml+xml,*/*";
- request.ContentType = "application/json";
-
- byte[] buffer = encoding.GetBytes(body);
- request.ContentLength = buffer.Length;
- request.GetRequestStream().Write(buffer, 0, buffer.Length);
-
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
- {
- return reader.ReadToEnd();
- }
- }
- catch (Exception ex)
- {
-
- return "POST报错:" + ex.Message;
- }
- }
- }
- }
|