以下是我正在使用的代码:
<cfsilent>
<cffunction name="getSignatureKey" returntype="binary" access="private" output="false" hint="Derive the sign-in key">
<cfargument name="key" type="string" required="true" />
<cfargument name="dateStamp" type="string" required="true" />
<cfargument name="regionName" type="string" required="true" />
<cfargument name="serviceName" type="string" required="true" />
<cfset Local.kSecret = charsetDecode("AWS4" & arguments.key, "UTF-8") />
<cfset Local.kDate = sign( arguments.dateStamp, Local.kSecret ) />
<cfset Local.kRegion = sign( arguments.regionName, Local.kDate ) />
<cfset Local.kService = sign( arguments.serviceName, Local.kRegion ) />
<cfset Local.kSigning = sign( "aws4_request", Local.kService ) />
<cfreturn Local.kSigning />
</cffunction>
<cffunction name="sign" returntype="binary" access="private" output="false" hint="Sign with NSA SHA-256 Algorithm">
<cfargument name="message" type="string" required="true" />
<cfargument name="key" type="binary" required="true" />
<cfargument name="algorithm" type="string" default="HmacSHA256" />
<cfargument name="encoding" type="string" default="UTF-8" />
<cfset Local.keySpec = createObject("java","javax.crypto.spec.SecretKeySpec") />
<cfset Local.keySpec = Local.keySpec.init( arguments.key, arguments.algorithm ) />
<cfset Local.mac = createObject("java","javax.crypto.Mac").getInstance( arguments.algorithm ) />
<cfset Local.mac.init( Local.keySpec ) />
<cfreturn Local.mac.doFinal( charsetDecode(arguments.message, arguments.encoding ) ) />
</cffunction>
</cfsilent>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AWS Test</title>
</head>
<body>
<cfset kSecret = getSignatureKey(
'mysecretaccesskey',
'20160408',
'us-west-1',
'AWSECommerceService'
) />
<cfset MyDateTime = now()>
<cfset urlstring="http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=myaccesskeyID&Timestamp=#DateFormat(MyDateTime,"YYYY-MM-DD")#T#TimeFormat(DateAdd('h', 5 , MyDateTime),'HH:MM:SS')#Z&Signature=#BinaryEncode(kSecret, 'hex')#&BrowseNodeId=2625373011&Operation=BrowseNodeLookup&ResponseGroup=TopSellers&Service=AWSECommerceService">
<cfdump var="#urlstring#">
<CFHTTP URL="#urlstring#" result="data">
<cfdump var="#data#">
</body>
</html>
我从Amazon AWS收到以下错误:
<?xml version="1.0" ?>
<BrowseNodeLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2005-10-05">
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
</Error>
<RequestId>28a54988-fda5-11e5-87c7-d5c13ae487c7</RequestId>
</BrowseNodeLookupErrorResponse>
我做错了什么?