SignedUrls { public static String signUrl(String url, byte[] key, String keyName, Date expirationTime) throws InvalidKeyException, NoSuchAlgorithmException { final long unixTime = expirationTime.getTime() / 1000; String urlToSign = url + (url.contains("?") ? "&" : "?") + "Expires=" + unixTime + "&KeyName=" + keyName; String encoded = SignedUrls.getSignature(key, urlToSign); return urlToSign + "&Signature=" + encoded; }  static String signUrl(String url,
                               byte[] key,
                               String keyName,
                               Date expirationTime); static String getSignature(byte[] privateKey, String input); static void main(String[] args);  }
@Test public void testUrlPath() throws Exception { String result = signUrl(BASE_URL + "foo", KEY_BYTES, KEY_NAME, EXPIRATION); final String expected = "https: assertEquals(result, expected); }
@Test public void testUrlParams() throws Exception { String result = signUrl(BASE_URL + "?param=true", KEY_BYTES, KEY_NAME, EXPIRATION); final String expected = "https: assertEquals(result, expected); }
@Test public void testStandard() throws Exception { String result = signUrl(BASE_URL, KEY_BYTES, KEY_NAME, EXPIRATION); final String expected = "https: assertEquals(result, expected); }