// Acquire an HMAC/SHA1 from the raw key bytes.
SecretKeySpec signingKey=
new SecretKeySpec(awsSecretAccessKey.getBytes(), HMAC_SHA1_ALGORITHM);
// Acquire the MAC instance and initialize with the signing key.
Mac mac=null;
try {
mac=Mac.getInstance(HMAC_SHA1_ALGORITHM);
}
catch(NoSuchAlgorithmException e) {
// should not happen
throw new RuntimeException("Could not find sha1 algorithm", e);
}
try {
mac.init(signingKey);
}
catch(InvalidKeyException e) {
// also should not happen
throw new RuntimeException("Could not initialize the MAC algorithm", e);
}
// Compute the HMAC on the digest, and set it.
String b64=Base64.encodeBytes(mac.doFinal(canonicalString.getBytes()));
if(urlencode) {
return urlencode(b64);
}
else {