Authenticating REST Requests

Every REST request requires a signature. The signature is used as the value for the Signature parameter in the URL being constructed. The string you use to compute the HMAC signature is constructed using one of the following two methods.

[Important]Important

For both signature methods, do not URL encode the concatenated string before computing the signature. URL encode the computed signature and other query parameters as specified in RFC1738, section 2.2. In addition, make sure to encode the + character although it is not required by RFC1738. This is required because the + character is interpreted as a blank space by Sun Java classes that perform URL decoding.

Signature version 1 is the recommended and more secure method of signing requests. This version catches spoofing of any of the request parameters.

The following is a Java code snippet that shows how to construct the string.

/*
* Assumes parameters are in a java.util.Map named paramMap
* where the key is the parameter name.
*/
Set<String> sortedKeys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
sortedKeys.addAll(paramMap.keySet());

// Don't include Signature in the string to sign.
sortedKeys.remove("Signature");

StringBuilder stringBuilder = new StringBuilder();
for(String key : sortedKeys) {
    stringBuilder.append(key);
    stringBuilder.append(paramMap.get(key));
    }

System.out.println("String to sign : " + stringBuilder.toString());

Signature Version 0 is a less secure, but simpler method to sign requests. The SignatureVersion query parameter is not necessary when using this version.

To calculate a signature (version 0)

  1. Concatenate the values of the Action and Timestamp request parameters, in that order.

    You can use the Expires parameter instead of Timestamp.

  2. Calculate an RFC 2104-compliant HMAC-SHA1 Signature, using your Secret Access Key as the key.

    For more information, go to http://www.faqs.org/rfcs/rfc2104.html.

  3. Convert the resulting value to base64.

  4. URL encode the resulting value as specified in RFC 1738, section 2.2

    This is required because base64 encoding can result in characters that are not legal in a URL, such as plus signs (+), slashes (/), and equal signs (=).

  5. Pass the final value in the Signature request parameter.