/// <summary> /// 获得待计算签名的字符串 /// </summary> /// <param name="canonicalRequest">canonicalRequest 字符串</param> /// <param name="formattedSigningDateTime">签名时间信息</param> /// <param name="scope">签名 scope 信息</param> /// <param name="signingAlgorithm">jd cloud signing algorithm</param> /// <returns>计算签名的字符串</returns> public static string CreateStringToSign(string canonicalRequest, string formattedSigningDateTime, string scope, string signingAlgorithm) { string stringToSign = new StringBuilder(signingAlgorithm) .Append(ParameterConstant.LINE_SEPARATOR) .Append(formattedSigningDateTime) .Append(ParameterConstant.LINE_SEPARATOR) .Append(scope) .Append(ParameterConstant.LINE_SEPARATOR) .Append(StringUtils.ByteToHex(SignUtil.SignHash(canonicalRequest), true)) .ToString(); return(stringToSign); }
/// <summary> /// 计算http content SHA256 hash 校验值 /// </summary> /// <param name="content">http 请求body信息</param> /// <returns>计算后的16进制加密的 content 信息</returns> public static string CalculateContentHash(byte[] content) { try { if (content == null || content.Length <= 0) { content = new byte[0]; } string contentSha256 = StringUtils.ByteToHex(SignUtil.SignHash(content), true); return(contentSha256); } catch (Exception ex) { throw new Exception("get the request content sha256 error", ex); } }