示例#1
0
        private async Task <HttpRequestMessage> BuildRequestMessage(HttpMethod method, Uri requestUri, HttpContent content,
                                                                    IMacService rsaPublicService, string signatureKey, string aesKey, string aesIv)
        {
            var requestMessage = new HttpRequestMessage
            {
                Method     = method,
                RequestUri = requestUri,
                Content    = content
            };

            //Timestamp
            var timestamp    = (DateTime.UtcNow - SSLConstants.Timestamp_StartUtcDateTime).TotalMilliseconds;
            var timestampStr = Convert.ToInt64(timestamp).ToString();

            requestMessage.Headers.Add(SSLConstants.HttpHeaders_Timestamp, timestampStr);

            //SignatureKey
            var encryptSignatureKey = rsaPublicService.Encrypt(signatureKey);

            requestMessage.Headers.Add(SSLConstants.HttpHeaders_SignatureKey, encryptSignatureKey);

            var shaService = GetSHAService(signatureKey);
            //Signature
            var signature = CalcRequestSignature(requestMessage, timestampStr, shaService);

            requestMessage.Headers.Add(SSLConstants.HttpHeaders_Signature, signature);

            //Securitykey
            var securityKey        = $"{aesKey}||{aesIv}";
            var encryptSecurityKey = rsaPublicService.Encrypt(securityKey);

            requestMessage.Headers.Add(SSLConstants.HttpHeaders_SecurityKey, encryptSecurityKey);

            //Encrypt Content
            var aesService = GetAESService(aesKey, aesIv);

            requestMessage.Content = await EncryptRequestContent(requestMessage, aesService);

            return(requestMessage);
        }
示例#2
0
        private static string CalcResponseSignature(HttpResponseMessage response, string timestamp, IMacService shaService)
        {
            var sourceStr = $"{(int)response.StatusCode} {timestamp}";

            return(shaService.Encrypt(sourceStr));
        }
示例#3
0
        private static string CalcRequestSignature(HttpRequestMessage request, string timestamp, IMacService shaService)
        {
            var sourceStr = $"{request.Method.Method.ToUpper()} {request.RequestUri.AbsolutePath} {timestamp}";

            return(shaService.Encrypt(sourceStr));
        }