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.epg.section.descriptor.servicelistdescriptor.ServiceListDescriptorTest.java

/**
 * Test of getServiceList method, of class ServiceListDescriptor.
 *///w  w w.  j a  v  a 2  s  .c o  m
@Test
public void testGetServiceList() throws DecoderException {
    LOG.info("getServiceList");
    ServiceListDescriptor instance = new ServiceListDescriptor(this.descs.getSERVICE_LIST_DESCRIPTOR());
    List<Service> expResult = new ArrayList<>();
    expResult.add(new Service(Hex.decodeHex("009701".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("009801".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("009901".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("02f1c0".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("02f3c0".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("02f4c0".toCharArray())));
    expResult.add(new Service(Hex.decodeHex("02f5c0".toCharArray())));

    List<Service> result = instance.getServiceList();
    assertEquals(expResult, result);
}

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

@Override
public String decrypt(String secretkey, String iv, String toDecrypt)
        throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException,
        BadPaddingException, InvalidAlgorithmParameterException, DecoderException {
    Cipher cipher = Cipher.getInstance(AESMODE);
    SecretKeySpec secretKeySpec = new SecretKeySpec(secretkey.getBytes(), AES);
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(Hex.decodeHex(iv.toCharArray())));
    return new String(cipher.doFinal(Base64.decodeBase64(toDecrypt)));
}

From source file:com.qubole.quark.catalog.db.encryption.MysqlAES.java

public String convertToEntityAttribute(String phrase) throws SQLException {
    try {//w  w w .j a v a  2  s.co m
        Cipher decryptCipher = Cipher.getInstance("AES");
        decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(this.key, "UTF-8"));

        return new String(decryptCipher.doFinal(Hex.decodeHex(phrase.toCharArray())));
    } catch (Exception e) {
        throw new SQLException(e);
    }

}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.XOPPartDataSource.java

public InputStream getInputStream() throws IOException {
    try {/*from   w  w w.  j  a  v a2s .  c o m*/
        if (source != null) {
            return new FileInputStream(source);
        }
        if (SchemaUtils.isInstanceOf(schemaType, XmlHexBinary.type)) {
            return new ByteArrayInputStream(Hex.decodeHex(content.toCharArray()));
        } else if (SchemaUtils.isInstanceOf(schemaType, XmlBase64Binary.type)) {
            return new ByteArrayInputStream(Base64.decodeBase64(content.getBytes()));
        } else if (SchemaUtils.isAnyType(schemaType)) {
            return new ByteArrayInputStream(content.getBytes());
        } else
            throw new IOException("Invalid type for XOPPartDataSource; " + schemaType.getName());
    } catch (Exception e) {
        SoapUI.logError(e);
        throw new IOException(e.toString());
    }
}

From source file:com.liferay.portal.util.CookieKeys.java

public static String getCookie(HttpServletRequest request, String name, boolean toUpperCase) {

    String value = CookieUtil.get(request, name, toUpperCase);

    if ((value != null) && isEncodedCookie(name)) {
        try {//ww w .  j  ava 2  s  .  co  m
            String encodedValue = value;
            String originalValue = new String(Hex.decodeHex(encodedValue.toCharArray()));

            if (_log.isDebugEnabled()) {
                _log.debug("Get encoded cookie " + name);
                _log.debug("Hex encoded value " + encodedValue);
                _log.debug("Original value " + originalValue);
            }

            return originalValue;
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e.getMessage());
            }

            return value;
        }
    }

    return value;
}

From source file:backtype.storm.security.serialization.BlowfishTupleSerializer.java

public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) {
    String encryption_key = null;
    try {//from  www.j a  v a 2  s.  com
        encryption_key = (String) storm_conf.get(SECRET_KEY);
        LOG.debug("Blowfish serializer being constructed ...");
        if (encryption_key == null) {
            throw new RuntimeException("Blowfish encryption key not specified");
        }
        byte[] bytes = Hex.decodeHex(encryption_key.toCharArray());
        _serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes);
    } catch (org.apache.commons.codec.DecoderException ex) {
        throw new RuntimeException("Blowfish encryption key invalid", ex);
    }
}

From source file:com.aqnote.shared.cryptology.symmetric.DES.java

public synchronized static String decrypt(String cryptotext) {
    try {// w  ww .jav  a  2 s  .c  om
        byte[] clearByte;
        if (cryptotext == null) {
            return null;
        }
        clearByte = decodeCipher.doFinal(Hex.decodeHex(cryptotext.toCharArray()));
        return new String(clearByte, ENCODE_UTF_8);
    } catch (IllegalStateException e) {
        throw new RuntimeException(e);
    } catch (IllegalBlockSizeException e) {
        throw new RuntimeException(e);
    } catch (BadPaddingException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    } catch (DecoderException e) {
        throw new RuntimeException(e);
    }
}

From source file:it.scoppelletti.programmerpower.security.spi.IVParameterSpecFactory.java

public AlgorithmParameterSpec newInstance(Properties props, String prefix) {
    String name, value;/*from   w  w w.  j  a  va  2 s  .  c o  m*/
    byte[] iv;
    AlgorithmParameterSpec param;

    name = Strings.concat(prefix, IVParameterSpecFactory.PROP_IV);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    try {
        iv = Hex.decodeHex(value.toCharArray());
    } catch (DecoderException ex) {
        throw SecurityUtils.toSecurityException(ex);
    }

    param = new IvParameterSpec(iv);

    return param;
}

From source file:com.haulmont.timesheets.EncryptDecrypt.java

private static byte[] decodeString(String string) throws DecoderException {
    if (string == null)
        return null;
    return Hex.decodeHex(string.toCharArray());
}

From source file:kij_chat_client.RC4.java

public String decrypt(final String ciphertext) {
    try {//w w  w .  ja v  a  2s.co m
        int[] cipherints = toInts(Hex.decodeHex(ciphertext.toCharArray()));
        for (int i = 0; i < cipherints.length; i++) {
            cipherints[i] = cipherints[i] & 0xff;
        }
        byte[] plaintext = toBytes(transform(cipherints));
        return new String(plaintext, Charset.forName("ASCII"));
    } catch (DecoderException e) {
    }
    return null;
}