public new void Sign <T>(IRequest <T> request, ICredentials credentials) { var sanitizedCredentials = this.SanitizeCredentials(credentials); var signerParams = new SignerRequestParams <T>(request, this.regionName, this.serviceName, "SDK-HMAC-SHA256"); this.AddHostHeader(request); request.AddHeader("X-Sdk-Date", signerParams.GetFormattedSigningDateTime()); String contentSha256 = this.CalculateContentHash(request); /* Not support for now * String contentSha256 = this.calculateContentHash(request); * if ("required".equals(request.getHeaders().get("x-sdk-content-sha256"))) * { * request.addHeader("x-sdk-content-sha256", contentSha256); * } * * String canonicalRequest = this.createCanonicalRequest(request, contentSha256); * string stringToSign = this.CreateStringToSign(canonicalRequest, signerParams); * byte[] signingKey = this.deriveSigningKey(sanitizedCredentials, signerParams); * byte[] signature = this.computeSignature(stringToSign, signingKey, signerParams); */ //byte[] signature = this.computeSignature(stringToSign, signingKey, signerParams); request.AddHeader("Authorization", this.BuildAuthorizationHeader(request, null, sanitizedCredentials, signerParams)); }
protected string CreateStringToSign <T>(string canonicalRequest, SignerRequestParams <T> signerParams) { var stringToSignBuilder = new StringBuilder(signerParams.GetSigningAlgorithm()); stringToSignBuilder.Append("\n") .Append(signerParams.GetFormattedSigningDateTime()) .Append("\n") .Append(signerParams.GetScope()) .Append("\n") .Append(BinaryUtils.ToHex(this.Hash(canonicalRequest))); var stringToSign = stringToSignBuilder.ToString(); return(stringToSign); }
private string BuildAuthorizationHeader <T>(IRequest <T> request, byte[] signature, ICredentials credentials, SignerRequestParams <T> signerParams) { var signingCredentials = credentials.GetAccessKeyId() + "/" + signerParams.GetScope(); var credential = "Credential=" + signingCredentials; var signerHeaders = "SignedHeaders=" + this.GetSignedHeadersString(request); var signatureHeader = "Signature=" + BinaryUtils.ToHex(signature); var authHeaderBuilder = new StringBuilder(); authHeaderBuilder.Append("SDK-HMAC-SHA256") .Append(" ") .Append(credential) .Append(", ") .Append(signerHeaders) .Append(", ") .Append(signatureHeader); return(authHeaderBuilder.ToString()); }