Example usage for org.apache.commons.codec.binary Hex Hex

List of usage examples for org.apache.commons.codec.binary Hex Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex Hex.

Prototype

public Hex() 

Source Link

Document

Creates a new codec with the default charset name #DEFAULT_CHARSET_NAME

Usage

From source file:com.lightboxtechnologies.spectrum.FsEntryUtilsTest.java

@Test
public void retrieveImageID() throws Exception {
    final Hex hex = new Hex();
    final byte[] hash = hex.decode("8a9111fe05f9815fc55c728137c5b389".getBytes());
    final byte[] key = makeFsEntryKey(hash, "/howdy/doody.jpg".getBytes(), 34);

    assertArrayEquals(hash, getImageID(key));
}

From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java

@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));
}

From source file:edu.unc.lib.dl.util.Checksum.java

/**
 * Get the checksum for the passed in byte array
 * /*from www. jav  a2 s.c om*/
 * @param byteArray
 *            must not be null
 * @return byte array containing checksum
 */
public String getChecksum(byte[] byteArray) {
    messageDigest.reset();
    messageDigest.update(byteArray);
    Hex hex = new Hex();
    return new String(hex.encode(messageDigest.digest()));
}

From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java

@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));
}

From source file:com.linuxbox.enkive.archiver.AbstractMessageArchivingService.java

public static String calculateMessageId(Message message) throws CannotArchiveException {
    String messageUUID = null;//from   w  ww .  j a v a 2  s.  c o m
    try {
        MessageDigest sha1calc = MessageDigest.getInstance("SHA-1");
        sha1calc.reset();
        messageUUID = new String(
                (new Hex()).encode(sha1calc.digest(message.getReconstitutedEmail().getBytes())));
    } catch (NoSuchAlgorithmException e) {
        throw new CannotArchiveException("Could not calculate UUID for message", e);
    } catch (IOException e) {
        throw new CannotArchiveException("Could not calculate UUID for message", e);
    }
    return messageUUID;
}

From source file:com.ewcms.common.io.HtmlStringUtil.java

public static String hexEncode(byte bs[]) {
    return new String((new Hex()).encode(bs));
}

From source file:com.proctorcam.proctorserv.HashedAuthenticator.java

/**  
 *  buildSig takes query(StringBuilder) as a parameter. After hashing query
 *  in Hex, the resulting signature (String) is returned.
 *//* w  w w  . j a va2  s .  c om*/

protected static String buildSig(StringBuilder query) {

    MessageDigest sha = null;
    try {
        sha = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException ex) {
        System.err.println(ex.getMessage());
    }

    byte[] hash = null;
    try {
        hash = sha.digest((query.toString()).getBytes("UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        System.err.println(ex.getMessage());
    }

    return new Hex().encodeHexString(hash);

}

From source file:fedorax.server.module.storage.lowlevel.irods.IrodsIFileSystem.java

private static final CopyResult stream2streamCopy(InputStream in, OutputStream out) throws IOException {
    int BUFFER_SIZE = 8192;
    LOG.debug("IrodsIFileSystem.stream2streamCopy() start");
    CopyResult result = new CopyResult();
    byte[] buffer = new byte[BUFFER_SIZE];
    int bytesRead = 0;
    try {//w  w w . j  a  v a 2 s .  com
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IOException("Cannot compare checksums without MD5 algorithm.", e);
        }
        messageDigest.reset();
        while ((bytesRead = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
            messageDigest.update(buffer, 0, bytesRead);
            result.size = result.size + bytesRead;
            // for transport failure test add the following line:
            // buffer[0] = '!';
            out.write(buffer, 0, bytesRead);
        }
        out.flush();
        Hex hex = new Hex();
        result.md5 = new String(hex.encode(messageDigest.digest()));
    } catch (IOException e) {
        LOG.error("Unexpected", e);
        throw e;
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            LOG.warn("Exception while trying to close jargon output stream", e);
        }
    }
    LOG.debug("IrodsIFileSystem.stream2streamCopy() end");
    return result;
}

From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java

@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));
}

From source file:edu.unc.lib.dl.util.Checksum.java

/**
 * Get the checksum for the passed in byte array
 * //from  w  w  w .ja v  a 2 s  . c  o m
 * @param byteArray
 *            must not be null
 * @return byte array containing checksum
 */
public String getChecksum(InputStream in) throws IOException {
    messageDigest.reset();
    try (BufferedInputStream bis = new BufferedInputStream(in, 1024)) {
        byte[] buffer = new byte[1024];
        int numRead;
        do {
            numRead = bis.read(buffer);
            if (numRead > 0) {
                messageDigest.update(buffer, 0, numRead);
            }
        } while (numRead != -1);
    }
    Hex hex = new Hex();
    return new String(hex.encode(messageDigest.digest()));
}