Package org.apache.commons.codec.binary

Examples of org.apache.commons.codec.binary.Hex


            // Compute the hmac on input data bytes
            byte[] rawHmac = mac.doFinal(message.getBytes(UTF_8));

            // Convert raw bytes to Hex
            byte[] hexBytes = new Hex().encode(rawHmac);

            // Covert array of Hex bytes to a String
            return new String(hexBytes, UTF_8);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
View Full Code Here


     * @return an instance of {@link ResourceChecksumSourceImpl} that uses MD5 and Hex encoding.
     * @since 3.0.3
     */
    protected ResourceChecksumSource createResourceChecksumSource()
    {
        return new ResourceChecksumSourceImpl("MD5", new Hex());
    }
View Full Code Here

     * @return
     */
    private static String displayByteFormat(Composite localComposite, byte[] byteArray, int numOfBytes,
                                            String encoding, String direction, boolean isHex)
    {
        final Hex hexeconder = new Hex();
        final byte[] encoded = hexeconder.encode(byteArray);

        int hexLength = byteArray.length * 2;
        StringBuilder sb = new StringBuilder();
        int currentBytePos = (Integer) localComposite.getData("currentBytePos");
        int startingBytePos = (Integer) localComposite.getData("startingBytePos");
View Full Code Here

* @author Joel Uckelman
*/
public class KeyUtilsTest {
@Test
  public void makeOutKeyMD5() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash =
      hex.decode("8a9111fe05f9815fc55c728137c5b389".getBytes());
    final byte type = 0;
    final byte[] col = "vassalengine.org/VASSAL 3.1.15".getBytes();

    // It's neat that I have to cast one-byte numeric literals to bytes.
    // Thanks, Java!
View Full Code Here

    assertArrayEquals(expected, KeyUtils.makeEntryKey(hash, type, col));
  }

  @Test
  public void makeOutKeySHA1() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash =
      hex.decode("64fa477898e268fd30c2bfe272e5a016f5ec31c4".getBytes());
    final byte type = 1;
    final byte[] col = "vassalengine.org/VASSAL 3.1.15".getBytes();

    // It's neat that I have to cast one-byte numeric literals to bytes.
    // Thanks, Java!
View Full Code Here

    assertArrayEquals(expected, KeyUtils.makeEntryKey(hash, type, col));
  }

  @Test
  public void retrieveMD5() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeef".getBytes());
    final byte[] entryID = FsEntryUtils.makeFsEntryKey(hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17);
    final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.MD5, entryID);
   
    assertArrayEquals(hash, KeyUtils.getHash(rowKey));
  }
View Full Code Here

    assertArrayEquals(hash, KeyUtils.getHash(rowKey));
  }

  @Test
  public void getHashLengthMD5() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeef".getBytes());
    final byte[] entryID = FsEntryUtils.makeFsEntryKey(hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17);
    final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.MD5, entryID);

    assertEquals(KeyUtils.MD5_LEN, KeyUtils.getHashLength(rowKey));
  }
View Full Code Here

    assertEquals(KeyUtils.MD5_LEN, KeyUtils.getHashLength(rowKey));
  }

  @Test
  public void retrieveSHA1() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes());
    final byte[] entryID = FsEntryUtils.makeFsEntryKey(hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17);
    final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID);

    assertArrayEquals(hash, KeyUtils.getHash(rowKey));
  }
View Full Code Here

    assertArrayEquals(hash, KeyUtils.getHash(rowKey));
  }

  @Test
  public void getHashLengthSHA1() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes());
    final byte[] entryID = FsEntryUtils.makeFsEntryKey(hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17);
    final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID);

    assertEquals(KeyUtils.SHA1_LEN, KeyUtils.getHashLength(rowKey));
  }
View Full Code Here

    assertEquals(KeyUtils.SHA1_LEN, KeyUtils.getHashLength(rowKey));
  }

  @Test
  public void retrieveFsEntryID() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes());
    final byte[] entryID = FsEntryUtils.makeFsEntryKey(hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17);
    final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID);

    assertArrayEquals(entryID, KeyUtils.getFsEntryID(rowKey));
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.codec.binary.Hex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.