/** * Converts byte data to a Hex-encoded string in lower case. * * @param data * data to hex encode. * * @return hex-encoded string. */ public static String toHex(byte[] data) { return Base16Lower.encodeAsString(data); }
/** * Converts a Hex-encoded data string to the original byte data. * * @param hexData * hex-encoded data to decode. * @return decoded data from the hex string. */ public static byte[] fromHex(String hexData) { return Base16Lower.decode(hexData); }
public String getSignature(ZonedDateTime now, String policy) { try { Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(("AWS4" + awsAccessSecret).getBytes("UTF-8"), "HmacSHA256")); byte[] dateKey = mac.doFinal(now.format(DateTimeFormatter.ofPattern("yyyyMMdd")).getBytes("UTF-8")); mac.init(new SecretKeySpec(dateKey, "HmacSHA256")); byte[] dateRegionKey = mac.doFinal(region.getBytes("UTF-8")); mac.init(new SecretKeySpec(dateRegionKey, "HmacSHA256")); byte[] dateRegionServiceKey = mac.doFinal("s3".getBytes("UTF-8")); mac.init(new SecretKeySpec(dateRegionServiceKey, "HmacSHA256")); byte[] signingKey = mac.doFinal("aws4_request".getBytes("UTF-8")); mac.init(new SecretKeySpec(signingKey, "HmacSHA256")); return Base16Lower.encodeAsString(mac.doFinal(policy.getBytes("UTF-8"))); } catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) { throw new AssertionError(e); } }
/** * Converts a Hex-encoded data string to the original byte data. * * @param hexData * hex-encoded data to decode. * @return decoded data from the hex string. */ public static byte[] fromHex(String hexData) { return Base16Lower.decode(hexData); }
/** * Converts byte data to a Hex-encoded string in lower case. * * @param data * data to hex encode. * * @return hex-encoded string. */ public static String toHex(byte[] data) { return Base16Lower.encodeAsString(data); }
/** * Converts a Hex-encoded data string to the original byte data. * * @param hexData * hex-encoded data to decode. * @return decoded data from the hex string. */ public static byte[] fromHex(String hexData) { return Base16Lower.decode(hexData); }
/** * Converts byte data to a Hex-encoded string in lower case. * * @param data * data to hex encode. * * @return hex-encoded string. */ public static String toHex(byte[] data) { return Base16Lower.encodeAsString(data); }