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:ch.rgw.tools.PasswordEncryptionService.java

public String getEncryptedPasswordAsHexString(String password, String salt)
        throws NoSuchAlgorithmException, InvalidKeySpecException, DecoderException {
    byte[] encryptedPassword = getEncryptedPassword(password, Hex.decodeHex(salt.toCharArray()));
    return Hex.encodeHexString(encryptedPassword);
}

From source file:com.mycompany.monroelabsm.B58.java

public static byte[] hexToBytes(String s) throws DecoderException {
    return Hex.decodeHex(s.toCharArray());
}

From source file:corner.services.impl.DESedeEncryptServiceImpl.java

public String decrypt(final String cryptograph) {
    if (cryptograph == null)
        return null;
    try {// w  w w .jav a 2s  . co  m
        // ?
        byte[] decoded = Hex.decodeHex(cryptograph.toCharArray());
        // cryptograph.getBytes(CHIPERH_CHARSET);

        // 
        byte[] srcBytes = decrypt(decoded, cipher.getCipher());

        if (srcBytes == null)
            return null;

        return new String(srcBytes, CHIPERH_CHARSET);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.microsoft.sqlserver.jdbc.datatypes.SQLServerSpatialDatatypeTest.java

@Test
public void testLineStringWkb() throws DecoderException {
    String geoWKT = "LINESTRING(1 0, 0 1, -1 0)";
    byte[] geomWKB = Hex.decodeHex(
            "00000000010403000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF000000000000000001000000010000000001000000FFFFFFFF0000000002"
                    .toCharArray());/*from  w  w w  .  j  ava 2  s  .  com*/
    byte[] geogWKB = Hex.decodeHex(
            "E61000000104030000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F0BF01000000010000000001000000FFFFFFFF0000000002"
                    .toCharArray());
    Geometry geomWKT = Geometry.deserialize(geomWKB);
    Geography geogWKT = Geography.deserialize(geogWKB);
    assertEquals(geomWKT.asTextZM(), geoWKT);
    assertEquals(geogWKT.asTextZM(), geoWKT);
}

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

@Test
public void testInvalidKeyAlgorithm() {
    try {//from  w  w  w  .j av  a2 s .com
        SecretKey key = new SecretKey("HMAC-SHA256", Hex.decodeHex("1234567890abcdef".toCharArray()));
        RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm();
        alg.verify(stringData.substring(1).getBytes("UTF-8"), Hex.decodeHex(hexSig.toCharArray()), key);
        Assert.fail();
    } catch (MagicSigException mse) {
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

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

public synchronized InputStream getInputStream() throws Exception {
    if (data != null)
        return new ByteArrayInputStream(data);

    AttachmentEncoding encoding = getEncoding();
    if (encoding == AttachmentEncoding.NONE)
        return bodyPart.getInputStream();

    data = Tools.readAll(bodyPart.getInputStream(), Tools.READ_ALL).toByteArray();

    if (encoding == AttachmentEncoding.BASE64) {
        if (Base64.isArrayByteBase64(data))
            data = Tools.readAll(new ByteArrayInputStream(Base64.decodeBase64(data)), Tools.READ_ALL)
                    .toByteArray();//w  w w  .ja  va 2  s .  c  o m
        else
            throw new Exception("Attachment content for part [" + getPart() + "] is not base64 encoded");
    } else if (encoding == AttachmentEncoding.HEX) {
        data = Hex.decodeHex(new String(data).toCharArray());
    }

    return new ByteArrayInputStream(data);
}

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

public ExtendedEventDescriptorItemTest() throws DecoderException {
    target = new ExtendedEventDescriptorItem(Hex.decodeHex(data));
}

From source file:be.fedict.eid.idp.model.CryptoUtil.java

public static Mac getMac(String encodedHmacSecret) throws DecoderException, InvalidKeyException {

    return getMac(Hex.decodeHex(encodedHmacSecret.toCharArray()));
}

From source file:com.knewton.mapreduce.example.StudentEventMapperTest.java

/**
 * Test the start time range filters in the mapper.
 *///from  www  .j  ava2 s . co  m
@Test
public void testMapWithStartRangeStudentEvents() throws Exception {
    conf.set(PropertyConstants.START_DATE.txt, "2013-03-28T23:03:02.394Z");
    underTest.setup(mockedContext);

    // send event outside of time range

    // Mar.28.2013.19:53:38.0.0
    DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    long eventId = dt.getMillis();

    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    Cell column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));

    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext, never()).write(any(LongWritable.class), any(StudentEventWritable.class));

    // send event inside of time range

    // Mar.29.2013.03:07:21.0.0
    dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    eventId = dt.getMillis();

    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext).write(any(LongWritable.class), any(StudentEventWritable.class));
}

From source file:de.betterform.xml.xforms.ui.UploadTest.java

/**
 * Tests ui element state.//from  w  w  w .jav a  2 s  . com
 *
 * @throws Exception if any error occurred during the test.
 */
public void testUploadHex() throws Exception {
    Upload upload = (Upload) this.xformsProcesssorImpl.getContainer().lookup("upload-hex");
    upload.getTarget().addEventListener(XFormsEventNames.VALUE_CHANGED, this.valueChangedListener, false);

    String filename = "UploadTest.xhtml";
    String mediatype = "application/xhtml+xml";

    BufferedInputStream bis = new BufferedInputStream(getClass().getResourceAsStream(filename));
    byte[] data = new byte[bis.available()];
    bis.read(data);
    upload.setValue(data, filename, mediatype);
    upload.getTarget().removeEventListener(XFormsEventNames.VALUE_CHANGED, this.valueChangedListener, false);

    assertEquals(new String(data), new String(Hex.decodeHex(((String) upload.getValue()).toCharArray())));
    assertEquals(filename, upload.getFilename().getValue());
    assertEquals(mediatype, upload.getMediatype().getValue());

    ModelItem modelItem = upload.getModel().getInstance(upload.getInstanceId())
            .getModelItem(upload.getInstanceNode());
    assertEquals(filename, modelItem.getFilename());
    assertEquals(mediatype, modelItem.getMediatype());

    assertEquals("upload-hex", this.valueChangedListener.getId());
}