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

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

Introduction

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

Prototype

public static char[] encodeHex(byte[] data) 

Source Link

Document

Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.

Usage

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

public String convertToDatabaseColumn(String phrase) throws SQLException {
    try {/*w w w .jav  a 2s .  co m*/
        Cipher encryptCipher = Cipher.getInstance("AES");
        encryptCipher.init(Cipher.ENCRYPT_MODE, generateMySQLAESKey(this.key, "UTF-8"));

        return new String(Hex.encodeHex(encryptCipher.doFinal(phrase.getBytes("UTF-8"))));
    } catch (Exception e) {
        throw new SQLException(e);
    }
}

From source file:de.berlin.magun.nfcmime.core.RfidDAO.java

/** 
 * @param tag Tag//from  ww w . j a v  a  2 s .c  o m
 * @return a hexadecimal String representation of a Tag's ID or UID
 */
public String getTagId(Tag tag) {

    // get the ID byte array
    byte[] id = tag.getId();

    if (NfcV.get(tag) != null) {
        ArrayUtils.reverse(id);
    }

    return new String(Hex.encodeHex(id));
}

From source file:com.sirius.utils.encrypt.DESEncryptor.java

@Override
public String encryptHex(Object key, String data) throws EncryptException {
    byte[] result = encrypt(key, data.getBytes());
    return new String(Hex.encodeHex(result));
}

From source file:net.sf.hajdbc.codec.hex.HexCodecFactory.java

/**
 * {@inheritDoc}/*from  ww  w . j a v a2 s .  c o  m*/
 * @see net.sf.hajdbc.codec.Codec#encode(java.lang.String)
 */
@Override
public String encode(String value) {
    return new String(Hex.encodeHex(value.getBytes()));
}

From source file:com.cedarsoft.app.PasswordUtilsTest.java

@Test
public void testIt() throws DecoderException {
    assertEquals("1a1dc91c907325c69271ddf0c944bc72",
            new String(Hex.encodeHex(PasswordUtils.calculateMD5Hash("pass"))));
    assertEquals("ea847988ba59727dbf4e34ee75726dc3",
            new String(Hex.encodeHex(PasswordUtils.calculateMD5Hash("topsecret"))));

    assertTrue(PasswordUtils.hasExpectedHash("pass",
            Hex.decodeHex("1a1dc91c907325c69271ddf0c944bc72".toCharArray())));
    assertTrue(PasswordUtils.hasExpectedHash("topsecret",
            Hex.decodeHex("ea847988ba59727dbf4e34ee75726dc3".toCharArray())));

    assertFalse(PasswordUtils.hasExpectedHash("topsecret", null));
    assertFalse(PasswordUtils.hasExpectedHash("topsecret", Hex.decodeHex("1234".toCharArray())));
}

From source file:com.talis.mapreduce.dicenc.SecondMapper.java

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String[] t = Utils.parseTripleOrQuad(value.toString());
    MessageDigest digest = null;/* w w  w .  ja va 2 s .c o m*/
    try {
        digest = MessageDigest.getInstance("MD5");
        for (String n : t) {
            digest.update((n + "|").getBytes("UTF-8"));
        }
        String hash = new String(Hex.encodeHex(digest.digest()));

        context.write(new Text(t[0]), new Text(hash + "-s"));
        context.write(new Text(t[1]), new Text(hash + "-p"));
        context.write(new Text(t[2]), new Text(hash + "-o"));
        if (t.length == 4) {
            context.write(new Text(t[3]), new Text(hash + "-g"));
        }
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

From source file:com.magic.util.HashCrypt.java

public static String getDigestHash(String str, String code, String hashType) {
    if (str == null)
        return null;
    try {/*  w  ww  .  java  2 s  . c  om*/
        byte codeBytes[] = null;

        if (code == null)
            codeBytes = str.getBytes();
        else
            codeBytes = str.getBytes(code);
        MessageDigest messagedigest = MessageDigest.getInstance(hashType);

        messagedigest.update(codeBytes);
        byte digestBytes[] = messagedigest.digest();
        char[] digestChars = Hex.encodeHex(digestBytes);
        ;
        return "{" + hashType + "}" + new String(digestChars, 0, digestChars.length);
    } catch (Exception e) {
        throw new GeneralRuntimeException("Error while computing hash of type " + hashType, e);
    }
}

From source file:com.intelligentz.appointmentz.controllers.register.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    MessageDigest messageDigest = null;
    try {/*  w w w .  ja v a 2s.c  o  m*/
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(register.class.getName()).log(Level.SEVERE, "Error:{0}", ex.toString());
    }
    messageDigest.reset();
    messageDigest.update(req.getParameter("form-password").getBytes(Charset.forName("UTF8")));
    final byte[] resultByte = messageDigest.digest();
    final String password = new String(Hex.encodeHex(resultByte));

    String userName = req.getParameter("form-hospital-id");
    String id = req.getParameter("form-id");
    //String password = req.getParameter("form-password");
    String hospitalName = req.getParameter("form-hospital-name");
    register(id, userName, password, hospitalName, req, res);

}

From source file:com.medsphere.ovid.common.uuid.KeyGenerator.java

public String getUUID() {
    long timeInMillis = System.currentTimeMillis();
    int timeLow = (int) timeInMillis & 0xFFFFFFFF;
    int node = seeder.nextInt();
    String ret = new String(Hex.encodeHex(intToByteArray(timeLow))) + middle
            + new String(Hex.encodeHex(intToByteArray(node)));
    return ret;/*  w w w.j av  a 2s.c  o m*/
}

From source file:com.intelligentz.appointmentz.controllers.authenticate.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    MessageDigest messageDigest = null;
    try {//from   w  ww . j  av a2s.c o m
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(authenticate.class.getName()).log(Level.SEVERE, "Error:{0}", ex.toString());
    }
    messageDigest.reset();
    messageDigest.update(req.getParameter("form-password").getBytes(Charset.forName("UTF8")));
    final byte[] resultByte = messageDigest.digest();
    final String password = new String(Hex.encodeHex(resultByte));

    String userName = req.getParameter("form-username");
    //String password = req.getParameter("form-password");
    authenticate(userName, password, req, res);

}