private String CreateAuthorization(Byte[] postData, IDictionary <String, String> headers, Uri uri, String service, String region, String accessID, String secretKey) { // lock이 없으면 400에러(Protocol Error)가 발생할 수 있다. lock (_lock) { Byte[] contentHash = AWS4SignerBase.CanonicalRequestHashAlgorithm.ComputeHash(postData); String contentHashString = AWS4SignerBase.ToHexString(contentHash, true); var signer = new AWS4SignerForPOST { EndpointUri = uri, HttpMethod = "POST", Service = service, Region = region }; String authorization = signer.ComputeSignature(headers, String.Empty, contentHashString, accessID, secretKey); return(authorization); } }
private void DoCreate(string awsKey, string awsSecret, string awsToken, string messageInput) { var createPath = "create"; var uri = new Uri(string.Format("https://{0}", BuildPath(createPath))); var bodyJson = JsonUtility.ToJson(new CreateMessageRequest(messageInput)); // Hashing content var contentHash = AWS4SignerBase.CanonicalRequestHashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(bodyJson)); var contentHashString = AWS4SignerBase.ToHexString(contentHash, true); var headers = new Dictionary <string, string> { { AWS4SignerBase.X_Amz_Content_SHA256, contentHashString }, { "content-length", bodyJson.Length.ToString() }, { "content-type", "application/json" }, { AWS4SignerBase.X_Amz_Security_Token, awsToken } }; var signer = new AWS4SignerForPOST { EndpointUri = uri, HttpMethod = "POST", Service = "execute-api", Region = ApiGatewayRegionField.text }; var authorization = signer.ComputeSignature( headers, string.Empty, contentHashString, awsKey, awsSecret); headers.Add("Authorization", authorization); var payloadBytes = Encoding.UTF8.GetBytes(bodyJson); headers.Remove("Host"); WWW www = new WWW(uri.AbsoluteUri, payloadBytes, headers); Send(www, (resp => { if (string.IsNullOrEmpty(www.error)) { Log(www.text); } else { Log("Error: " + www.error); } })); }