use of org.apache.commons.codec.binary.Hex in project nem2-sdk-java by nemtech.
the class HexEncoder method getString.
/**
* Converts a byte array to a hex string.
*
* @param bytes The input byte array.
* @return The output hex string.
*/
public static String getString(final byte[] bytes) {
final Hex codec = new Hex();
final byte[] decodedBytes = codec.encode(bytes);
return StringEncoder.getString(decodedBytes);
}
use of org.apache.commons.codec.binary.Hex in project nem2-sdk-java by nemtech.
the class HexEncoder method getBytesInternal.
private static byte[] getBytesInternal(final String hexString) throws DecoderException {
final Hex codec = new Hex();
final String paddedHexString = 0 == hexString.length() % 2 ? hexString : "0" + hexString;
final byte[] encodedBytes = StringEncoder.getBytes(paddedHexString);
return codec.decode(encodedBytes);
}
use of org.apache.commons.codec.binary.Hex in project esup-papercut by EsupPortail.
the class HashService method getHMac.
public String getHMac(String input) {
try {
Mac mac = Mac.getInstance("HmacSHA512");
mac.init(secretKey);
final byte[] macData = mac.doFinal(input.getBytes());
byte[] hex = new Hex().encode(macData);
String hmac = new String(hex, "ISO-8859-1").toUpperCase();
log.debug(input);
log.debug(hmac);
return hmac;
} catch (Exception e) {
log.error("Error during encoding data ...");
throw new RuntimeException(e);
}
}
Aggregations