@Test public void testCryptoHash () throws Exception { String body = "x-vol-tenant-domain=t419.sandbox.mozu-qa.com&x-vol-return-url=https: String secretKey = "b2dc973d5dec4bd6aa325fa906a64aee"; String dateString = "Mon, 18 Aug 2014 21:07:21 GMT"; String hash1 = Crypto.getHash(secretKey, dateString, body); String hash2 = Crypto.getHash(secretKey, dateString, body); assertEquals(hash1, hash2); assertEquals("yJ+gMQm3FZzKfgySi+1jGYcUcSADVjr3x19BwKyFj9w=", hash1); }
public static String getHash(String secretKey, String date, String body) { String hash = null; try { logger.info("Shared secret: {}, date: {}, body: {}", secretKey, date, body); MessageDigest digest = MessageDigest.getInstance(MozuConfig.getEncodeAlgorithm()); String doubleSecretKey = secretKey.concat(secretKey); String hashedSecret = Base64.encodeBase64String(digest.digest(doubleSecretKey.getBytes(MozuConfig.getCharSet()))); String payload = hashedSecret.concat(date).concat(body); hash = Base64.encodeBase64String(digest.digest(payload.getBytes(MozuConfig.getCharSet()))); logger.info("Generated hash: {}", hash); } catch (NoSuchAlgorithmException nae) { logger.error("Bad encoding algorithm " + MozuConfig.getEncodeAlgorithm() + ": " + nae.getMessage() ); } catch (UnsupportedEncodingException uee) { logger.error("Unsupported character set: " + MozuConfig.getCharSet() + ": " + uee.getMessage() ); } return hash; }
Crypto { public static String getHash(String secretKey, String date, String body) { String hash = null; try { logger.info("Shared secret: {}, date: {}, body: {}", secretKey, date, body); MessageDigest digest = MessageDigest.getInstance(MozuConfig.getEncodeAlgorithm()); String doubleSecretKey = secretKey.concat(secretKey); String hashedSecret = Base64.encodeBase64String(digest.digest(doubleSecretKey.getBytes(MozuConfig.getCharSet()))); String payload = hashedSecret.concat(date).concat(body); hash = Base64.encodeBase64String(digest.digest(payload.getBytes(MozuConfig.getCharSet()))); logger.info("Generated hash: {}", hash); } catch (NoSuchAlgorithmException nae) { logger.error("Bad encoding algorithm " + MozuConfig.getEncodeAlgorithm() + ": " + nae.getMessage() ); } catch (UnsupportedEncodingException uee) { logger.error("Unsupported character set: " + MozuConfig.getCharSet() + ": " + uee.getMessage() ); } return hash; } }
Crypto { public static String getHash(String secretKey, String date, String body) { String hash = null; try { logger.info("Shared secret: {}, date: {}, body: {}", secretKey, date, body); MessageDigest digest = MessageDigest.getInstance(MozuConfig.getEncodeAlgorithm()); String doubleSecretKey = secretKey.concat(secretKey); String hashedSecret = Base64.encodeBase64String(digest.digest(doubleSecretKey.getBytes(MozuConfig.getCharSet()))); String payload = hashedSecret.concat(date).concat(body); hash = Base64.encodeBase64String(digest.digest(payload.getBytes(MozuConfig.getCharSet()))); logger.info("Generated hash: {}", hash); } catch (NoSuchAlgorithmException nae) { logger.error("Bad encoding algorithm " + MozuConfig.getEncodeAlgorithm() + ": " + nae.getMessage() ); } catch (UnsupportedEncodingException uee) { logger.error("Unsupported character set: " + MozuConfig.getCharSet() + ": " + uee.getMessage() ); } return hash; }  }
Crypto { public static String getHash(String secretKey, String date, String body) { String hash = null; try { logger.info("Shared secret: {}, date: {}, body: {}", secretKey, date, body); MessageDigest digest = MessageDigest.getInstance(MozuConfig.getEncodeAlgorithm()); String doubleSecretKey = secretKey.concat(secretKey); String hashedSecret = Base64.encodeBase64String(digest.digest(doubleSecretKey.getBytes(MozuConfig.getCharSet()))); String payload = hashedSecret.concat(date).concat(body); hash = Base64.encodeBase64String(digest.digest(payload.getBytes(MozuConfig.getCharSet()))); logger.info("Generated hash: {}", hash); } catch (NoSuchAlgorithmException nae) { logger.error("Bad encoding algorithm " + MozuConfig.getEncodeAlgorithm() + ": " + nae.getMessage() ); } catch (UnsupportedEncodingException uee) { logger.error("Unsupported character set: " + MozuConfig.getCharSet() + ": " + uee.getMessage() ); } return hash; }  static String getHash(String secretKey, String date, String body); static boolean isRequestValid(Map<String, String> reqHeaders, String body); static boolean isRequestValid(HttpServletRequest request, String body); static final boolean isRequestValid(ApiContext apiContext, String body); }
Crypto { public static String getHash(String secretKey, String date, String body) { String hash = null; try { logger.info("Shared secret: {}, date: {}, body: {}", secretKey, date, body); MessageDigest digest = MessageDigest.getInstance(MozuConfig.getEncodeAlgorithm()); String doubleSecretKey = secretKey.concat(secretKey); String hashedSecret = Base64.encodeBase64String(digest.digest(doubleSecretKey.getBytes(MozuConfig.getCharSet()))); String payload = hashedSecret.concat(date).concat(body); hash = Base64.encodeBase64String(digest.digest(payload.getBytes(MozuConfig.getCharSet()))); logger.info("Generated hash: {}", hash); } catch (NoSuchAlgorithmException nae) { logger.error("Bad encoding algorithm " + MozuConfig.getEncodeAlgorithm() + ": " + nae.getMessage() ); } catch (UnsupportedEncodingException uee) { logger.error("Unsupported character set: " + MozuConfig.getCharSet() + ": " + uee.getMessage() ); } return hash; }  static String getHash(String secretKey, String date, String body); static boolean isRequestValid(Map<String, String> reqHeaders, String body); static boolean isRequestValid(HttpServletRequest request, String body); static final boolean isRequestValid(ApiContext apiContext, String body);  }