Search in sources :

Example 6 with Hex

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);
}
Also used : Hex(org.apache.commons.codec.binary.Hex)

Example 7 with Hex

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);
}
Also used : Hex(org.apache.commons.codec.binary.Hex)

Example 8 with Hex

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);
    }
}
Also used : Hex(org.apache.commons.codec.binary.Hex) Mac(javax.crypto.Mac)

Aggregations

Hex (org.apache.commons.codec.binary.Hex)8 Mac (javax.crypto.Mac)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Test (org.junit.Test)1