Example usage for org.apache.commons.codec.binary Hex decodeHex

List of usage examples for org.apache.commons.codec.binary Hex decodeHex

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex decodeHex.

Prototype

public static byte[] decodeHex(char[] data) throws IllegalArgumentException 

Source Link

Document

Converts an array of characters representing hexadecimal values into an array of bytes of those same values.

Usage

From source file:com.cliqset.magicsig.algorithm.test.HMACSHA256MagicSignatureAlgorithmTest.java

@Test
public void testExceptionVerifyNullKey() {
    try {/*from   ww w.  j  a  va  2  s .co m*/
        HMACSHA256MagicSigAlgorithm alg = new HMACSHA256MagicSigAlgorithm();
        alg.verify(stringData.substring(1).getBytes("UTF-8"), Hex.decodeHex(hexSig.toCharArray()), null);
        Assert.fail();
    } catch (IllegalArgumentException iae) {
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:libepg.epg.section.descriptor.shorteventdescriptor.ShortEventDescriptorTest.java

/**
 * Test of getEvent_name_char method, of class ShortEventDescriptor.
 *//*from   w  ww  .  j  av  a2 s . c  om*/
@Test
public void testGetEvent_name_char() throws DecoderException {
    LOG.debug("getEvent_name_char");
    ShortEventDescriptor instance = target;
    byte[] expResult = Hex.decodeHex(
            "1b7ceff3eff3d1c3b3ed1b7ea11b7cade3e91b7dc8e21b7cef213cebc9212148741b7dd33d50bb1b7ea13f4d35241b7cbdf3b01b242a3b1b7dfad6faea"
                    .toCharArray());
    byte[] result = instance.getEvent_name_char();
    assertArrayEquals(expResult, result);
}

From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitterTest.java

/**
 * Test of getSplittedPayLoad method, of class PayLoadSplitter.
 *
 * @throws org.apache.commons.codec.DecoderException
 *//*from  w  ww  .  j av a 2  s  .  c o  m*/
@Test
public void testGetSplittedPayLoad02() throws DecoderException {
    LOG.debug("getSplittedPayLoad_ ??");
    TsPacket packet = this.testData.getEit20();

    PayLoadSplitter instance = new PayLoadSplitter();
    instance.setPacket(packet);
    Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> expResult = new HashMap<>();
    expResult.put(PayLoadSplitter.PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE, Hex.decodeHex(
            "4ef0c10409d100017fe17fe1014e44f5dfe123000000300000a64d6f6a706e11487ece5464fe412afb432afc1b243b7a56593f483661ca1d46f91d5ef243663f34cbfd487e3d5134553e5ef20e33c4ce1d441d5cc7efabeae4b9af0f3b58466eb9eb3f3734363350487e3d5148564148fa3a233273cffb432afcfa304646624c7221274170342240354d3a5006f1b3006a706e5406a2ff22ff84ffc10184c409f203100fff6f6a706ec70e0008300501136a706e006a70"
                    .toCharArray()));
    Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> result = instance.getSplittedPayLoad();

    assertEquals(expResult.size(), result.size());

    Set<PayLoadSplitter.PAYLOAD_PART_KEY> expResKeys = expResult.keySet();
    Set<PayLoadSplitter.PAYLOAD_PART_KEY> resKeys = result.keySet();
    assertEquals(expResKeys, resKeys);

    for (PayLoadSplitter.PAYLOAD_PART_KEY key : resKeys) {
        byte[] expResBytes = expResult.get(key);
        byte[] ResBytes = result.get(key);
        assertArrayEquals("?", expResBytes, ResBytes);

    }
}

From source file:com.cliqset.magicsig.algorithm.test.RSASHA256MagicSignatureAlgorithmTest.java

@Test
public void testExceptionVerifyNullData() {
    try {//from ww w  . j av a  2s.c o  m
        MagicKey key = new MagicKey(magicKey.getBytes("ASCII"));
        RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm();
        alg.verify(null, Hex.decodeHex(hexSig.toCharArray()), key);
        Assert.fail();
    } catch (IllegalArgumentException iae) {
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.netcrest.pado.internal.security.AESCipher.java

public static String decryptHexToText(String hexStr) throws Exception {
    byte[] buf = Hex.decodeHex(hexStr.toCharArray());
    return decryptBinaryToText(buf);
}

From source file:com.continusec.client.ObjectHash.java

private static final byte[] hashString(String s, String r) throws ContinusecException {
    if (r != null && s.startsWith(r)) {
        try {/* w w  w .  ja  v  a2s.  co m*/
            return Hex.decodeHex(s.substring(r.length()).toCharArray());
        } catch (DecoderException e) {
            throw new InvalidObjectException(e);
        }
    } else {
        try {
            MessageDigest d = DigestUtils.getSha256Digest();
            d.update((byte) 'u');
            d.update(Normalizer.normalize(s, Normalizer.Form.NFC).getBytes("UTF8"));
            return d.digest();
        } catch (UnsupportedEncodingException e) {
            throw new InvalidObjectException(e);
        }
    }
}

From source file:libepg.epg.util.datetime.DateTimeFieldConverterTest.java

/**
 * Test of BytesToSqlDateTime method, of class DateTimeFieldConverter.
 *
 * @throws java.lang.Exception/*from  ww  w.  ja  v a2 s  .c  o  m*/
 */
@Test
public void testBytesTOSqlDateTime2() throws Exception {
    LOG.info("BytesTOSqlDateTime2");
    byte[] source = Hex.decodeHex("e07c180000".toCharArray());
    Timestamp expResult = new Timestamp(
            new java.text.SimpleDateFormat("yyyyMMddHHmmss").parse("20160321180000").getTime());
    Timestamp result = DateTimeFieldConverter.BytesToSqlDateTime(source);
    assertEquals(expResult, result);
}

From source file:com.axelor.apps.account.ebics.xml.InitializationRequestElement.java

/**
 * Decodes an hexadecimal input./*from w w w. j  a v a 2 s.com*/
 * @param hex the hexadecimal input
 * @return the decoded hexadecimal value
 * @throws EbicsException
 */
protected byte[] decodeHex(byte[] hex) throws AxelorException {
    if (hex == null) {
        throw new AxelorException("Bank digest is empty, HPB request must be performed before",
                IException.CONFIGURATION_ERROR);
    }

    try {
        return Hex.decodeHex((new String(hex)).toCharArray());
    } catch (DecoderException e) {
        throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR);
    }
}

From source file:de.resol.vbus.HeaderTest.java

@Test
public void testCheckMsbs() throws Exception {
    byte[] testBuffer1 = Hex.decodeHex("0123456789".toCharArray());
    assertEquals(true, Header.checkMsbs(testBuffer1, 0, testBuffer1.length - 1));
    assertEquals(false, Header.checkMsbs(testBuffer1, 0, testBuffer1.length));
}

From source file:com.bitbreeds.webrtc.sctp.messaging.SCTPServiceTest.java

@Test
public void testDataIntput() throws DecoderException {

    String dataInput = "1388138869086b5b2c030e9c0003001c436cf1d40000000d0000003348656c6c6f20576f726c6421";
    String m = "1388 1388 69086b5b 2c030e9c 00 03 001c 436cf1d40000000d000000334865 6c6c6f20576f726c6421";

    byte[] out = srv.handleRequest(Hex.decodeHex(dataInput.toCharArray())).get(0);

}