签名应用及示例(V4版本) 生成签名密钥 依次生成签名密钥,步骤如下: kDateHMACSHA256("AWS4"+{SecrectKey}, dateStamp) kRegionHMACSHA256(kDate, regionName) kServiceHMACSHA256(kRegion, serviceName) kSigningHMACSHA256(kService, "aws4request") 得到签名密钥kSigning后,就可以计算得到Signature signatureHex(HMACSHA256(kSigning, stringToSign)) 构造 Authorization Header 根据生成的签名构造 Authorization Header: Authorization: {algorithm} Credential{Credential}, SignedHeaders{SignedHeaders}, Signature{signature} shell示例 以上传对象为例: bash !/bin/sh accessKey"访问密钥ID" secretKey"私有访问密钥" regionName"cn" serviceName"s3" http or https protocol"https" host"gdoss.xstore.ctyun.cn" bucketName"testbucket" objectKey"testobj" sourceFile"/path/to/file" httpMethod"PUT" dateStamp$(date u +"%Y%m%d") requestDate$(date u +"%Y%m%dT%H%M%SZ") acl"publicreadwrite" contentType"text/plain" Canonical Request canonicalUri"/${bucketName}/${objectKey}" canonicalQueryString"" canonicalHeaders"contenttype:${contentType}nhost:${host}nxamzacl:${acl}nxamzdate:${requestDate}n" signedHeaders"contenttype;host;xamzacl;xamzdate" canonicalRequest"${httpMethod}n${canonicalUri}n${canonicalQueryString}n${canonicalHeaders}n${signedHeaders}nUNSIGNEDPAYLOAD" Canonical Request Hash canonicalRequestHash$(echo en "${canonicalRequest}" iconv t utf8 openssl dgst sha256 awk '{print $2}') String to Sign algorithm"AWS4HMACSHA256" credentialScope"${dateStamp}/${regionName}/${serviceName}/aws4request" stringToSign"${algorithm}n${requestDate}n${credentialScope}n${canonicalRequestHash}" 生成签名密钥 kDate$(echo en "${dateStamp}" openssl dgst sha256 hmac "AWS4${secretKey}" binary) kRegion$(echo en "${regionName}" openssl dgst sha256 mac HMAC macopt hexkey:$(echo en "${kDate}" xxd p c 256) binary) kService$(echo en "${serviceName}" openssl dgst sha256 mac HMAC macopt hexkey:$(echo en "${kRegion}" xxd p c 256) binary) kSigning$(echo en "aws4request" openssl dgst sha256 mac HMAC macopt hexkey:$(echo en "${kService}" xxd p c 256) binary)