I am trying for days(!) to sign the following string with SHA256 with a secret key: "aaa" the result should be (URL endcoded) : kvoJVZMPomuGyYP3cmiJkYz2L3usuZNfh2f9LaUxO3U%3D
Can anyone help please ?
GET
sellercentral.amazon.com
/gp/mws/registration/register.html
AWSAccessKeyId=AKIAFJPPO5KLY6G4XO7Q&SignatureMethod=HmacSHA256&SignatureVersion=2&id=1014f5ad-c359-4e86-8e50-bb8f8e431a9e&returnPathAndParameters=%2Forders%2FlistRecentOrders.jsp%3FsessionId%3D123
This is the code I am using but I can't get the same result:
private static final String QUERY = "GET\n"+
"sellercentral.amazon.com\n"+
"/gp/mws/registration/register.html\n"+
"AWSAccessKeyId=AKIAFJPPO5KLY6G4XO7Q&SignatureMethod=HmacSHA256&SignatureVersion=2&id=1014f5ad-c359-4e86-8e50-bb8f8e431a9e&returnPathAndParameters=%2Forders%2FlistRecentOrders.jsp%3FsessionId%3D123";
public static void main(String[] args) throws Exception {
System.out.println(encode("aaa", QUERY));
}
public static String encode(String key, String data) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
return Base64.encodeBase64String(sha256_HMAC.doFinal(data.getBytes()));
}