0
String stringToSign = "GET" + "\n" +
"webservices.amazon.com" + "\n" +
"/onca/xml" + "\n" +
"AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&ItemId=0679722769&Operation=ItemLookup&ResponeGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&Version=2009-01-06";
SecretKeySpec keySpec = new SecretKeySpec(
"1234567890".getBytes(),
"HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(keySpec);
byte[] result = mac.doFinal(stringToSign.getBytes());
String encodedResult = Base64.encodeBase64String(result);
System.out.println("encodedResult: "+encodedResult);
String urlEncodedResult = URLEncoder.encode(encodedResult, "UTF-8").replace("+", "%2B").replace("*", "%2A").replace("%7E", "~");
System.out.println("ulrEncodedResult: "+urlEncodedResult);
這是針對AWS的REST身份驗證。結果我得到的是: ulrEncodedResult:K1T%2FqvVoXgEvmdFhTEh71vLDznqEVCyKcslA5RRSB6s%3DSHA256 HMAC未給出預期的答案
預期的結果是: ulrEncodedResult:M%2Fy0%2BEAFFGaUAp4bWv%2FWEuXYah99pVsxvqtAuC8YN7I%3D
所有認證的具體步驟是在這裏展示:http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/rest-signature.html
任何人都可以發現我正在犯的錯誤嗎?
試過,不幸的是給出了相同的結果。 – fusi0n
當我嘗試.getBytes(「UTF-8」)和.getBytes()他們給出不同的結果,就像他們應該的,但總的來說結果保持不變... – fusi0n
有沒有人有想法? – fusi0n