現在webサービスのフォーム値をawsのs3に保存しようとしているのですが,v2認証がうまくいきません.

awsのドキュメントでは以下の手順で署名を作成するように記述されています.

Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;

Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );

StringToSign = HTTP-Verb + "\n" +
    Content-MD5 + "\n" +
    Content-Type + "\n" +
    Date + "\n" +
    CanonicalizedAmzHeaders +
    CanonicalizedResource;

CanonicalizedResource = [ "/" + Bucket ] +
    <HTTP-Request-URI, from the protocol name up to the query string> +
    [ subresource, if present. For example "?acl", "?location", "?logging", or "?torrent"];

CanonicalizedAmzHeaders = <described below>

そして同ページで以下のようなサンプルがかかれています.

-----------------request--------------------------------
GET /photos/puppy.jpg HTTP/1.1
Host: johnsmith.s3.amazonaws.com
Date: Tue, 27 Mar 2007 19:36:42 +0000

Authorization: AWS AKIAIOSFODNN7EXAMPLE:
bWq2s1WEIj+Ydj0vQ697zp+IXMU=

--------------------stringToSign-----------------------
GET\n
\n
\n
Tue, 27 Mar 2007 19:36:42 +0000\n
/johnsmith/photos/puppy.jpg

これらのサンプルを元に署名処理を書きました.
具体的には以下のようにかきました.

```
var accessKey = 'AKIAIOSFODNN7EXAMPLE'
var secretKey = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
var stringToSign = `
GET\n
\n
\n
Tue, 27 Mar 2007 19:36:42 +0000\n
/johnsmith/photos/puppy.jpg
`
//UTF-8-Encoding-Of( StringToSign )
var enStringToSign = encodeURI(stringToSign);
//HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign )
var hmacSha1 = CryptoJS.HmacSHA1(secretKey, enStringToSign);
//Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );
var signature = CryptoJS.enc.Base64.stringify(hmacSha1);
var authorization = `AWS ${accessKey}:${signature}`;
console.log(authorization)
//"AWS AKIAIOSFODNN7EXAMPLE:KXQrJvmB8Mr4qb6x5wVxcgEdBM8="
```

sample通り

```
AWS AKIAIOSFODNN7EXAMPLE:
bWq2s1WEIj+Ydj0vQ697zp+IXMU=
```

と出力されません.
どこが悪いかわかる方教えていただけると助かります

環境

  • os
    windows
  • 言語
    javascript
  • ライブラリ
    crypto.js