Difference between revisions of "Template:Json API HMAC Block- Java"
From Updox API
Line 1: | Line 1: | ||
− | public static void generateHmacHeaders(HttpURLConnection connection) throws Exception | + | public static void generateHmacHeaders(HttpURLConnection connection) throws Exception |
− | + | { | |
− | final SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss (z)"); <span style="color:green">// Create the date string</span> | + | final SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss (z)"); <span style="color:green">// Create the date string</span> |
− | + | d.setTimeZone(TimeZone.getTimeZone("GMT")); | |
− | + | final String timestampString = d.format(new Date()); | |
− | + | final String message = applicationId + ":" + applicationPassword + ":" + timestampString;<span style="color:green">// Create the message</span> | |
− | + | final String auth = "HMAC " + hmacSha1ToBase64(message, apiSecret); <span style="color:green">// Create the authorization hash</span> | |
− | + | connection.setRequestProperty("updox-timestamp", timestampString); <span style="color:green">// Set the request headers</span> | |
− | + | connection.setRequestProperty("Authorization", auth); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + |
Revision as of 16:08, 27 November 2013
public static void generateHmacHeaders(HttpURLConnection connection) throws Exception { final SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss (z)"); // Create the date string d.setTimeZone(TimeZone.getTimeZone("GMT")); final String timestampString = d.format(new Date()); final String message = applicationId + ":" + applicationPassword + ":" + timestampString;// Create the message final String auth = "HMAC " + hmacSha1ToBase64(message, apiSecret); // Create the authorization hash connection.setRequestProperty("updox-timestamp", timestampString); // Set the request headers connection.setRequestProperty("Authorization", auth); }