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.eventinformationtable.EventInformationTableRepeatingPartTest.java

/**
 * Test of getData method, of class EventInformationTableRepeatingPart.
 *///w  w w  .  j  a va 2 s .  c  o  m
@Test
public void testGetData() throws DecoderException {
    LOG.debug("getData");
    EventInformationTableRepeatingPart instance = target;
    byte[] expResult = Hex.decodeHex(data);
    byte[] result = instance.getData();
    assertArrayEquals(expResult, result);
}

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

@Test
public void testExceptionVerifyNullSig() {
    try {/*from ww  w  .ja v a 2s.  c  om*/
        SecretKey key = new SecretKey("HMAC-SHA256", Hex.decodeHex(hexKey.toCharArray()));
        HMACSHA256MagicSigAlgorithm alg = new HMACSHA256MagicSigAlgorithm();
        alg.verify(stringData.getBytes("UTF-8"), null, key);
        Assert.fail();
    } catch (IllegalArgumentException iae) {
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:libepg.epg.section.eit.descriptor.extendedeventdescriptor.ExtendedEventDescriptorItemTest.java

/**
 * Test of getiItem_description method, of class
 * ExtendedEventDescriptorItem./*  ww w . j a  va  2  s  .  c  o m*/
 */
@Test
public void testGetiItem_description() throws DecoderException {
    LOG.debug("getiItem_description");
    ExtendedEventDescriptorItem instance = target;
    byte[] expResult = Hex.decodeHex("4856414846624d46".toCharArray());
    byte[] result = instance.getiItem_description();
    assertArrayEquals(expResult, result);
}

From source file:ch.cyberduck.core.azure.AzureWriteFeature.java

@Override
public StatusOutputStream<Void> write(final Path file, final TransferStatus status,
        final ConnectionCallback callback) throws BackgroundException {
    try {/*from   w w w .  ja v a2 s . c om*/
        final CloudAppendBlob blob = session.getClient()
                .getContainerReference(containerService.getContainer(file).getName())
                .getAppendBlobReference(containerService.getKey(file));
        if (StringUtils.isNotBlank(status.getMime())) {
            blob.getProperties().setContentType(status.getMime());
        }
        final HashMap<String, String> headers = new HashMap<>();
        // Add previous metadata when overwriting file
        headers.putAll(status.getMetadata());
        blob.setMetadata(headers);
        // Remove additional headers not allowed in metadata and move to properties
        if (headers.containsKey(HttpHeaders.CACHE_CONTROL)) {
            blob.getProperties().setCacheControl(headers.get(HttpHeaders.CACHE_CONTROL));
            headers.remove(HttpHeaders.CACHE_CONTROL);
        }
        if (headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
            blob.getProperties().setCacheControl(headers.get(HttpHeaders.CONTENT_TYPE));
            headers.remove(HttpHeaders.CONTENT_TYPE);
        }
        final Checksum checksum = status.getChecksum();
        if (Checksum.NONE != checksum) {
            switch (checksum.algorithm) {
            case md5:
                try {
                    blob.getProperties().setContentMD5(
                            Base64.toBase64String(Hex.decodeHex(status.getChecksum().hash.toCharArray())));
                    headers.remove(HttpHeaders.CONTENT_MD5);
                } catch (DecoderException e) {
                    // Ignore
                }
                break;
            }
        }
        final BlobRequestOptions options = new BlobRequestOptions();
        options.setConcurrentRequestCount(1);
        options.setStoreBlobContentMD5(preferences.getBoolean("azure.upload.md5"));
        final BlobOutputStream out;
        if (status.isAppend()) {
            options.setStoreBlobContentMD5(false);
            out = blob.openWriteExisting(AccessCondition.generateEmptyCondition(), options, context);
        } else {
            out = blob.openWriteNew(AccessCondition.generateEmptyCondition(), options, context);
        }
        return new VoidStatusOutputStream(out) {
            @Override
            protected void handleIOException(final IOException e) throws IOException {
                if (StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) {
                    log.warn(String.format("Ignore failure %s", e));
                    return;
                }
                final Throwable cause = ExceptionUtils.getRootCause(e);
                if (cause instanceof StorageException) {
                    throw new IOException(e.getMessage(),
                            new AzureExceptionMappingService().map((StorageException) cause));
                }
                throw e;
            }
        };
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Upload {0} failed", e, file);
    } catch (URISyntaxException e) {
        throw new NotfoundException(e.getMessage(), e);
    }
}

From source file:libepg.epg.section.eventinformationtable.descriptor.extendedeventdescriptor.ExtendedEventDescriptorItemTest.java

/**
 * Test of getiItem_description method, of class
 * ExtendedEventDescriptorItem.//w  w w .j  av a 2s . c om
 */
@Test
public void testGetiItem_description() throws DecoderException {
    LOG.info("getiItem_description");
    ExtendedEventDescriptorItem instance = target;
    byte[] expResult = Hex.decodeHex("4856414846624d46".toCharArray());
    byte[] result = instance.getiItem_description();
    assertArrayEquals(expResult, result);
}

From source file:com.demandware.vulnapp.challenge.impl.ECBOracleChallenge.java

/**
 * test method, user will never decrypt// www .  j a  v  a  2  s. c om
 * @throws DecoderException 
 */
private String decryptValue(String str)
        throws IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, DecoderException {
    byte[] dec = Hex.decodeHex(str.toCharArray());
    byte[] decBytes = this.dCipher.doFinal(dec);
    return new String(decBytes).trim();
}

From source file:libepg.epg.section.descriptor.contentdescriptor.NibbleTest.java

/**
 * Test of equals method, of class Descriptor.
 *///from w  w w.j  av a 2 s.com
@Test
public void testEquals_ng() throws DecoderException, Throwable {
    LOG.debug("equals_ng");
    Nibble instance1 = NIbbleMaker.init(Hex.decodeHex("82ff".toCharArray()));
    Nibble instance2 = NIbbleMaker.init(Hex.decodeHex("81ff".toCharArray()));
    boolean result = instance1.equals(instance2);
    boolean expResult = false;
    assertEquals(expResult, result);
}

From source file:libepg.util.bytearray.ByteArraySplitterTest.java

/**
 * Test of splitByLengthField method, of class ByteArraySplitter.
 *
 * @throws org.apache.commons.codec.DecoderException
 *//*from w  w w. jav  a  2 s. c o  m*/
@Test
public void testSplitByLengthField_4args() throws DecoderException {
    LOG.debug("splitByLengthField");
    byte[] src = Hex.decodeHex(
            "0408f31020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f00104080409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe080588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32"
                    .toCharArray());
    int lengthFieldPosition = 4;
    int lengthFieldLength = 2;
    List<byte[]> expResult = new ArrayList<>();
    expResult.add(Hex.decodeHex(
            "0408f31020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f0010408".toCharArray()));//??????
    expResult.add(
            Hex.decodeHex("0409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08".toCharArray()));
    expResult.add(
            Hex.decodeHex("040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe08".toCharArray()));
    expResult.add(Hex.decodeHex(
            "0588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32".toCharArray()));
    List<byte[]> result = ByteArraySplitter.splitByLengthField(src, lengthFieldPosition, lengthFieldLength,
            (x) -> x & 0x0FFF);

    Iterator<byte[]> it_result = result.iterator();
    Iterator<byte[]> it_expResult = expResult.iterator();
    while (it_result.hasNext() && it_expResult.hasNext()) {
        StringBuilder s = new StringBuilder();
        byte[] res = it_result.next();
        byte[] expRes = it_expResult.next();
        if (Arrays.equals(res, expRes) == false) {
            fail("???????");
        } else {
            s.append(Hex.encodeHexString(expRes));
            s.append(" = ");
            s.append(Hex.encodeHexString(res));
            LOG.debug(s.toString());
        }
    }
}

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

@Test
@ExpectedExceptionMessage("^?????.*$")
public void testBytesTOSqlDateTime3() throws Exception {
    LOG.debug("BytesTOSqlDateTime_??");
    byte[] source = Hex.decodeHex("C07912450000".toCharArray());
    Timestamp result = DateTimeFieldConverter.BytesToSqlDateTime(source);
}

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

@Test
@ExpectedExceptionMessage("^??????????.*$")
public void testBytesTOSqlDateTime4() throws Exception {
    LOG.info("_60");
    byte[] source = Hex.decodeHex("e07c186000".toCharArray());
    Timestamp result = DateTimeFieldConverter.BytesToSqlDateTime(source);
}