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:libepg.util.bytearray.ByteDataBlockTest.java

/**
 * Test of toString method, of class ByteDataBlock.
 *///w  ww  . j ava 2  s.  c o m
@Test
public void testToString() throws DecoderException {
    LOG.debug("toString");
    ByteDataBlock instance = new ByteDataBlock(Hex.decodeHex(dat.p0d));
    String expResult = Hex.encodeHexString(instance.getData());
    String result = instance.toString();
    assertEquals(expResult, result);
}

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

@Test
public void testSign() {
    try {/*from  ww w .j av a2s  . co  m*/
        MagicKey key = new MagicKey(magicKey.getBytes("ASCII"));

        RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm();
        byte[] sig = alg.sign(stringData.getBytes("UTF-8"), key);

        Assert.assertArrayEquals(Hex.decodeHex(hexSig.toCharArray()), sig);

    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.blackcrowsys.sinscrypto.AesKeyGenerator.java

@Override
public SecretKey generateSecretKey(String password, String salt)
        throws NoSuchAlgorithmException, InvalidKeySpecException, DecoderException {
    SecretKeyFactory factory = SecretKeyFactory.getInstance(ALGORITHM);
    KeySpec spec = new PBEKeySpec(password.toCharArray(), Hex.decodeHex(salt.toCharArray()), ITERATION,
            KEYLENGTH);/* w  w w . j  a v a  2 s .  co  m*/
    SecretKey key = factory.generateSecret(spec);
    return new SecretKeySpec(key.getEncoded(), ENCRYPTION);
}

From source file:com.sap.core.odata.core.uri.expression.TestTokenizer.java

public static String HexToBase64(final String hex) {
    String base64 = "";
    byte bArr[];//  w w  w  .  j a va2 s  . com
    try {
        bArr = Hex.decodeHex(hex.toCharArray());
        base64 = Base64.encodeBase64String(bArr);
    } catch (DecoderException e) {
        fail("Error in Unittest preparation ( HEX->base64");
    }
    return base64;
}

From source file:com.knewton.mapreduce.util.SerializationUtilsTest.java

/**
 * Test if a deserializer can be instantiated correctly from a Hadoop conf property.
 * /*from  w w  w. j  a  v  a 2s.  co m*/
 * @throws TException
 * @throws DecoderException
 */
@Test
public void testDeserializerInstantiation() throws TException, DecoderException {
    Configuration conf = new Configuration();
    conf.set(SerializationUtils.SERIALIZATION_FACTORY_PARAMETER, TCompactProtocol.Factory.class.getName());
    TDeserializer deserializer = SerializationUtils.getDeserializerFromContext(conf);
    assertNotNull(deserializer);

    StudentEventData sed = new StudentEventData();
    byte[] studentEventDataBytes = Hex.decodeHex(eventDataString.toCharArray());
    deserializer.deserialize(sed, studentEventDataBytes);
    assertNotNull(sed.getBook());
    assertNotNull(sed.getCourse());
    assertNotNull(sed.getType());
    assertNotEquals(0L, sed.getScore());
    assertNotEquals(0L, sed.getStudentId());
    assertNotEquals(0L, sed.getTimestamp());
}

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

@Test
public void testSign() {
    try {//from  w  w  w  . j  av a2 s  . c o  m
        SecretKey key = new SecretKey("HMAC-SHA256", Hex.decodeHex(hexKey.toCharArray()));
        HMACSHA256MagicSigAlgorithm alg = new HMACSHA256MagicSigAlgorithm();
        byte[] sig = alg.sign(stringData.getBytes("UTF-8"), key);

        Assert.assertArrayEquals(Hex.decodeHex(hexSig.toCharArray()), sig);

    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:net.sourceforge.jaulp.crypto.aes.HexDump.java

/**
 * Transform the given array of characters representing hexadecimal values into an array of
 * bytes.// w ww. j  a  va  2  s  .co  m
 * 
 * @param data
 *            the array of characters
 * @return A byte array that contains the binary data decoded from the given char array.
 * @throws DecoderException
 *             is thrown if an odd number or illegal of characters is supplied
 */
public static byte[] decodeHex(char[] data) throws DecoderException {
    return Hex.decodeHex(data);
}

From source file:client.Client.java

static String fromHex(String input) {
    try {//  w ww.ja  va  2s.co  m
        return new String(Hex.decodeHex(input.toCharArray()));
    } catch (Exception e) {
        return new String();
    }
}

From source file:mitm.common.util.HexUtils.java

public static byte[] hexDecode(String hex, byte[] defaultIfNull) throws DecoderException {
    if (hex == null) {
        return defaultIfNull;
    }/* w  w w  .  j av a 2 s  .co m*/

    return Hex.decodeHex(hex.toCharArray());
}

From source file:com.cloudant.sync.datastore.encryption.EncryptionTestConstants.java

private static byte[] hexStringToByteArray(String s) {
    try {/*ww  w.j a  v  a  2 s .  co m*/
        return Hex.decodeHex(s.toCharArray());
    } catch (DecoderException ex) {
        // Crash the tests at this point, we've input bad data in our hard-coded values
        throw new RuntimeException("Error decoding hex data: " + s);
    }
}