| | |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using static Azure.Core.HttpHeader; |
| | | using System.Security.Cryptography; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net.Security; |
| | | using System.Security.Cryptography.X509Certificates; |
| | | using Org.BouncyCastle.Crypto.Parameters; |
| | | using Org.BouncyCastle.Security; |
| | | |
| | | namespace NewPdaSqlServer.service.QC; |
| | | |
| | |
| | | // private const string SPK = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApobID/gwmD9OofMG1gEcE94NCMeTYUq1cam/7ADZmxHCVpF143GaHWhqDdY0TTVbcUElsQ71DzAG2j3itWlIJBK5fVGwCo3sPpAvUDdKMh+Uivcp7yxdy/IDRA/PS4JARuEyM4cVJLhIOU2KnSlbIkheeoDkDgfaxu9kKrWnozJLiYraVTVDz9PdRX7fQdP+Zu/xB9txAGw4kvOm9HwgrzaSRdZEhisTJ5yyoNW/dLXtWKXA0cKhKOOIFu12TOrv/It6hl1ShTUuy79Pa51M9Oc2dEfVs1tluNXPWo1uFXQbBaJxdqZEJJlK7iW2uQFIao2O4XFHYThwy2+6116LtwIDAQAB"; |
| | | private const string HOST = "http://192.168.1.149:8099"; |
| | | |
| | | private const string SPK = @"-----BEGIN PUBLIC KEY----- |
| | | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApobID/gwmD9OofMG1gEc |
| | | E94NCMeTYUq1cam/7ADZmxHCVpF143GaHWhqDdY0TTVbcUElsQ71DzAG2j3itWlI |
| | | JBK5fVGwCo3sPpAvUDdKMh+Uivcp7yxdy/IDRA/PS4JARuEyM4cVJLhIOU2KnSlb |
| | | IkheeoDkDgfaxu9kKrWnozJLiYraVTVDz9PdRX7fQdP+Zu/xB9txAGw4kvOm9Hwg |
| | | rzaSRdZEhisTJ5yyoNW/dLXtWKXA0cKhKOOIFu12TOrv/It6hl1ShTUuy79Pa51M |
| | | 9Oc2dEfVs1tluNXPWo1uFXQbBaJxdqZEJJlK7iW2uQFIao2O4XFHYThwy2+6116L |
| | | twIDAQAB |
| | | -----END PUBLIC KEY-----"; |
| | | private const string SPK = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApobID/gwmD9OofMG1gEcE94NCMeTYUq1cam/7ADZmxHCVpF143GaHWhqDdY0TTVbcUElsQ71DzAG2j3itWlIJBK5fVGwCo3sPpAvUDdKMh+Uivcp7yxdy/IDRA/PS4JARuEyM4cVJLhIOU2KnSlbIkheeoDkDgfaxu9kKrWnozJLiYraVTVDz9PdRX7fQdP+Zu/xB9txAGw4kvOm9HwgrzaSRdZEhisTJ5yyoNW/dLXtWKXA0cKhKOOIFu12TOrv/It6hl1ShTUuy79Pa51M9Oc2dEfVs1tluNXPWo1uFXQbBaJxdqZEJJlK7iW2uQFIao2O4XFHYThwy2+6116LtwIDAQAB"; |
| | | |
| | | |
| | | public static class RsaHelper |
| | | { |
| | | public static string Encrypt(string plainText, string publicKeyPem) |
| | | { |
| | | // 将PEM格式的公钥转换为XML格式 |
| | | var rsa = RSA.Create(); |
| | | rsa.ImportFromPem(publicKeyPem); // 使用.NET 5+ 内置PEM解析方法 |
| | | //// 将PEM格式的公钥转换为XML格式 |
| | | //var rsa = RSA.Create(); |
| | | //rsa.ImportFromPem(publicKeyPem); // 使用.NET 5+ 内置PEM解析方法 |
| | | |
| | | var parameters = rsa.ExportParameters(false); |
| | | string publicKeyXml = $"<RSAKeyValue><Modulus>{Convert.ToBase64String(parameters.Modulus)}</Modulus><Exponent>{Convert.ToBase64String(parameters.Exponent)}</Exponent></RSAKeyValue>"; |
| | | //var parameters = rsa.ExportParameters(false); |
| | | //string publicKeyXml = $"<RSAKeyValue><Modulus>{Convert.ToBase64String(parameters.Modulus)}</Modulus><Exponent>{Convert.ToBase64String(parameters.Exponent)}</Exponent></RSAKeyValue>"; |
| | | |
| | | using var rsaProvider = new RSACryptoServiceProvider(); |
| | | rsaProvider.FromXmlString(publicKeyXml); // 使用转换后的XML格式公钥 |
| | | //using var rsaProvider = new RSACryptoServiceProvider(); |
| | | //rsaProvider.FromXmlString(publicKeyXml); // 使用转换后的XML格式公钥 |
| | | |
| | | var data = Encoding.UTF8.GetBytes(plainText); |
| | | var encrypted = rsaProvider.Encrypt(data, false); |
| | | return Convert.ToBase64String(encrypted); |
| | | //var data = Encoding.UTF8.GetBytes(plainText); |
| | | //var encrypted = rsaProvider.Encrypt(data, false); |
| | | //return Convert.ToBase64String(encrypted); |
| | | |
| | | RsaKeyParameters publicKeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(publicKeyPem)); |
| | | string XML = string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent></RSAKeyValue>", |
| | | Convert.ToBase64String(publicKeyParam.Modulus.ToByteArrayUnsigned()), |
| | | Convert.ToBase64String(publicKeyParam.Exponent.ToByteArrayUnsigned())); |
| | | string encryptedContent = string.Empty; |
| | | using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) |
| | | { |
| | | rsa.FromXmlString(XML); |
| | | byte[] encryptedData = rsa.Encrypt(Encoding.Default.GetBytes(plainText), false); |
| | | encryptedContent = Convert.ToBase64String(encryptedData); |
| | | } |
| | | return encryptedContent; |
| | | } |
| | | } |
| | | |
| | |
| | | public string GetToken() |
| | | { |
| | | |
| | | |
| | | ; |
| | | var userId = "1268"; |
| | | var encryptedUserId = RsaHelper.Encrypt(userId, SPK); |
| | | ; |
| | | var headers = new Dictionary<string, string> |
| | | { |
| | | ["appid"] = APPID, |
| | | ["secret"] = RsaHelper.Encrypt(SECRET, SPK) |
| | | ["secret"] = RsaHelper.Encrypt(SECRET, SPK), |
| | | ["userId"] = encryptedUserId |
| | | }; |
| | | |
| | | try |
| | |
| | | //} |
| | | |
| | | // 加密处理 |
| | | var userId = "FRadmin"; |
| | | var userId = "1268"; |
| | | var encryptedUserId = RsaHelper.Encrypt(userId, SPK); |
| | | string strToken = GetToken(); |
| | | |
| | | |
| | | // 替换原有的测试数据构建 |
| | | // 替换原有的测mainDataDict试数据构建 |
| | | mainDataDict = BuildMainDataFromQuery(query); |
| | | |
| | | |
| | |
| | | var request = WebRequest.Create(url) as HttpWebRequest; |
| | | request.Method = "POST"; |
| | | request.Timeout = 20000; |
| | | request.ContentType = "application/json; charset=utf-8"; // 修改为JSON格式 |
| | | request.ContentType = "application/x-www-form-urlencoded"; // 修改为JSON格式 |
| | | |
| | | // 构建请求头 |
| | | request.Headers.Add("appid", APPID); |
| | | request.Headers.Add("token", token); |
| | | request.Headers.Add("Content-Type", APPID); |
| | | request.Headers.Add("userId", encryptedUserId); |
| | | request.Headers.Set("appid", APPID); |
| | | request.Headers.Set("token", token); |
| | | request.Headers.Set("Content-Type", "application/x-www-form-urlencoded"); |
| | | request.Headers.Set("userId", encryptedUserId); |
| | | // 假设需要加密的userid从其他地方获取,这里需要补充获取逻辑 |
| | | |
| | | // 构建请求体 |
| | |
| | | var mainData = new Dictionary<string, object> |
| | | { |
| | | // 表结构定义 |
| | | ["tableDBName"] = "formtable_main_1356_dt1", |
| | | ["tableDBName"] = "formtable_main_33", |
| | | ["workflowRequestTableRecords"] = new List<Dictionary<string, object>> |
| | | { |
| | | new Dictionary<string, object> |