| | |
| | | |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | long currentTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); |
| | | string key = $"appkey=1830415116987195392×tamp={currentTimestamp}"; |
| | | string authorization = "Open " + GetStr(key); |
| | | //æ£å¼ |
| | | string authorization = "AppKey 1830415116987195392"; |
| | | //æµè¯ |
| | | //string authorization = "AppKey 1773317109539201024"; |
| | | |
| | | |
| | | headers = new Dictionary<string, string> |
| | | { |
| | | { "Appkey", "1830415116987195392" }, |
| | | { "Authorization", authorization }, |
| | | { "site_tenant_id", "ced19269-2b83-4577-be43-8cc2f700251e" } |
| | | //æ£å¼ |
| | | { "Site_tenant_id", "0dc2d164-8a62-417e-8a00-808007464feb" } |
| | | //æµè¯ |
| | | //{ "Site_tenant_id", "ced19269-2b83-4577-be43-8cc2f700251e" } |
| | | }; |
| | | if (headers != null) |
| | | { |
| | |
| | | { |
| | | Logger.Add(serviceAddress, requestJson == null ? "" : requestJson, result, beginDate); |
| | | } |
| | | } |
| | | public static string GetStr(string textToEncrypt) |
| | | { |
| | | string publicKey; |
| | | string privateKey; |
| | | GenerateRSAKeyPair(out publicKey, out privateKey); |
| | | byte[] encryptedBytes = RSAEncrypt(textToEncrypt, publicKey); |
| | | // å¯ä»¥å°å å¯åçåèæ°ç»è½¬æ¢ä¸ºBase64å符串æ¹ä¾¿åç»å¤çï¼ä¾å¦ä¼ è¾ç |
| | | string encryptedBase64 = Convert.ToBase64String(encryptedBytes); |
| | | return encryptedBase64; |
| | | } |
| | | public static void GenerateRSAKeyPair(out string publicKey, out string privateKey) |
| | | { |
| | | using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048)) |
| | | { |
| | | publicKey = rsa.ToXmlString(false); |
| | | privateKey = rsa.ToXmlString(true); |
| | | } |
| | | } |
| | | public static byte[] RSAEncrypt(string plainText, string publicKey) |
| | | { |
| | | byte[] encryptedData; |
| | | using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) |
| | | { |
| | | rsa.FromXmlString(publicKey); |
| | | // å°ææ¬è½¬æ¢ä¸ºUTF8ç¼ç çåèæ°ç» |
| | | byte[] plainBytes = Encoding.UTF8.GetBytes(plainText); |
| | | // 使ç¨SHA1åå¸ç®æ³ä»¥åPkcs1å¡«å
è§åè¿è¡å å¯ |
| | | encryptedData = rsa.Encrypt(plainBytes, true); |
| | | } |
| | | return encryptedData; |
| | | } |
| | | } |
| | | } |