public static String encryptReqXml(String rsaPrivateKey, String strDesKey, SortedDictionary <String, String> dic) { XmlDocument xmldoc = sortedDictionary2AllXml(dic); String smlStr = ConvertXmlToString(xmldoc); String sha256SourceSignString = SHAUtil.encryptSHA256(smlStr); System.Diagnostics.Debug.WriteLine("xml摘要:" + sha256SourceSignString); byte[] encyptBytes = RSACoder.encryptByPrivateKey(sha256SourceSignString, rsaPrivateKey); String sign = Convert.ToBase64String(encyptBytes, Base64FormattingOptions.InsertLineBreaks); String data = smlStr.Replace("</jdpay>", "<sign>" + sign + "</sign></jdpay>"); System.Diagnostics.Debug.WriteLine("封装后:" + data); byte[] key = Convert.FromBase64String(strDesKey); String encrypt = Des3.Des3EncryptECB(key, data); System.Diagnostics.Debug.WriteLine("3DES后:" + encrypt); encrypt = Convert.ToBase64String(Encoding.UTF8.GetBytes(encrypt)); System.Diagnostics.Debug.WriteLine("base64后:" + encrypt); SortedDictionary <String, String> reqdic = new SortedDictionary <string, string>(); reqdic.AddOrReplace("version", dic.getVaule("version")); reqdic.AddOrReplace("merchant", dic.getVaule("merchant")); reqdic.AddOrReplace("encrypt", encrypt); XmlDocument reqXml = new XmlDocument(); sortedDictionary2Xml(reqXml, reqdic); String reqXmlStr = ConvertXmlToString(reqXml); System.Diagnostics.Debug.WriteLine("请求xml:" + reqXmlStr); return(reqXmlStr); }
public static String signRemoveSelectedKeys(SortedDictionary <String, String> dic, String rsaPriKey, List <String> signKeyList) { //获取签名需要字符串和类型 String sourceSignString = SignUtil.signString(dic, signKeyList); //System.Diagnostics.Debug.WriteLine("签名原串:" + sourceSignString); //摘要 String sha256SourceSignString = SHAUtil.encryptSHA256(sourceSignString); //System.Diagnostics.Debug.WriteLine("sha256摘要:" + sha256SourceSignString); byte[] newsks = RSACoder.encryptByPrivateKey(sha256SourceSignString, rsaPriKey); return(Convert.ToBase64String(newsks, Base64FormattingOptions.InsertLineBreaks)); }