Java Code Examples for org.apache.commons.codec.binary.Hex#decode()

The following examples show how to use org.apache.commons.codec.binary.Hex#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicKey5.java    From dbys with GNU General Public License v3.0 5 votes vote down vote up
public static String generateSignature(String appCertificate, short service, String appID, int unixTs, int salt, String channelName, long uid, int expiredTs, TreeMap<Short, String> extra) throws Exception {
    // decode hex to avoid case problem
    Hex hex = new Hex();
    byte[] rawAppID = hex.decode(appID.getBytes());
    byte[] rawAppCertificate = hex.decode(appCertificate.getBytes());

    Message m = new Message(service, rawAppID, unixTs, salt, channelName, (int)(uid & 0xFFFFFFFFL), expiredTs, extra);
    byte[] toSign = pack(m);
    return new String(Hex.encodeHex(DynamicKeyUtil.encodeHMAC(rawAppCertificate, toSign), false));
}
 
Example 2
Source File: ConvertUtils.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an hex back to an byte array.
 *
 * @param hexString the hex string input
 * @return the byte array.
 */
public static byte[] fromHexToBytes(String hexString) {
    final Hex codec = new Hex();
    try {
        return codec.decode(StringEncoder.getBytes(hexString));
    } catch (DecoderException e) {
        throw new IllegalArgumentException(
            hexString + " could not be decoded. " + ExceptionUtils
                .getMessage(e), e);
    }
}
 
Example 3
Source File: ConvertUtils.java    From symbol-sdk-java with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 4
Source File: HexEncoder.java    From nem.core with MIT License 4 votes vote down vote up
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);
}