private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode) { // 第一个字母+长度+> int signDataStartIndex = indexOfRootNode + rootNode.Length + 1; string xmlStartNode = "<" + AlipayConstants.ENCRYPT_NODE_NAME + ">"; string xmlEndNode = "</" + AlipayConstants.ENCRYPT_NODE_NAME + ">"; int indexOfEncryptNode = body.IndexOf(xmlEndNode); if (indexOfEncryptNode < 0) { EncryptParseItem item = new EncryptParseItem(); item.encryptContent = null; item.startIndex = 0; item.endIndex = 0; return(item); } int startIndex = signDataStartIndex + xmlStartNode.Length; int bizLen = indexOfEncryptNode - startIndex; string encryptBizContent = body.Substring(startIndex, bizLen); EncryptParseItem item2 = new EncryptParseItem(); item2.encryptContent = encryptBizContent; item2.startIndex = signDataStartIndex; item2.endIndex = indexOfEncryptNode + xmlEndNode.Length; return(item2); }
private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode) { int signDataStartIndex = indexOfRootNode + rootNode.Length + 2; int indexOfSign = body.IndexOf("\"" + AlipayConstants.SIGN + "\""); int signDataEndIndex = indexOfSign - 1; if (signDataEndIndex < 0) { signDataEndIndex = body.Length - 1; } int length = signDataEndIndex - signDataStartIndex; string encyptContent = body.Substring(signDataStartIndex + 1, length - 2); EncryptParseItem item = new EncryptParseItem(); item.encryptContent = encyptContent; item.startIndex = signDataStartIndex; item.endIndex = signDataEndIndex; return(item); }
public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset) { EncryptParseItem item = ParseEncryptData(request, body); string bodyIndexContent = body.Substring(0, item.startIndex); string bodyEndContent = body.Substring(item.endIndex); string encryptContent = AlipayEncrypt.AesDencrypt(encryptKey, item.encryptContent, charset); return(bodyIndexContent + encryptContent + bodyEndContent); }
public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset) { if (!"AES".Equals(encryptType)) { throw new AopException("API only support AES!"); } EncryptParseItem item = parseEncryptData(request, body); string bodyIndexContent = body.Substring(0, item.startIndex); string bodyEndexContent = body.Substring(item.endIndex); //TODO 解密逻辑 string bizContent = AlipayEncrypt.AesDencrypt(encryptKey, item.encryptContent, charset); return(bodyIndexContent + bizContent + bodyEndexContent); }
private static EncryptParseItem ParseEncryptData(IAopRequest <T> request, string body) { string rootNode = request.GetApiName().Replace(".", "_") + AlipayConstants.RESPONSE_SUFFIX; string errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.IndexOf(rootNode); int indexOfErrorRoot = body.IndexOf(errorRootNode); EncryptParseItem result = null; if (indexOfRootNode > 0) { result = ParseEncryptItem(body, rootNode, indexOfRootNode); } else if (indexOfErrorRoot > 0) { result = ParseEncryptItem(body, errorRootNode, indexOfErrorRoot); } return(result); }