use of org.apache.commons.codec.binary.Hex in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class WhenEncoding method shouldConvertToHex.
@Test
public void shouldConvertToHex() throws DecoderException {
String text = randomString();
String actual = Encoding.HEX.encode(text.getBytes(CHAR_SET));
assertEquals("Text", text, new String(new Hex().decode(actual.getBytes(CHAR_SET)), CHAR_SET));
}
use of org.apache.commons.codec.binary.Hex in project algoliasearch-client-java by algolia.
the class APIClient method hmac.
static String hmac(String key, String msg) {
Mac hmac;
try {
hmac = Mac.getInstance("HmacSHA256");
} catch (NoSuchAlgorithmException e) {
throw new Error(e);
}
try {
hmac.init(new SecretKeySpec(key.getBytes(), "HmacSHA256"));
} catch (InvalidKeyException e) {
throw new Error(e);
}
byte[] rawHmac = hmac.doFinal(msg.getBytes());
byte[] hexBytes = new Hex().encode(rawHmac);
return new String(hexBytes);
}
use of org.apache.commons.codec.binary.Hex in project nem-library by rosklyar.
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 ninja by ninjaframework.
the class Crypto method signHmacSha1.
private String signHmacSha1(String value, String key) {
try {
// Get an hmac_sha1 key from the raw key bytes
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
// Get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
// Compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(value.getBytes(StandardCharsets.UTF_8));
// Convert raw bytes to Hex
byte[] hexBytes = new Hex().encode(rawHmac);
// Convert array of Hex bytes to a String
return new String(hexBytes, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.commons.codec.binary.Hex in project nem-library by rosklyar.
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);
}
Aggregations