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.agiletec.plugins.jpnewsletter.aps.system.services.newsletter.util.ShaEncoder.java

public static String encodeWord(String word, String salt) throws NoSuchAlgorithmException {
    String saltedPass = mergeWordAndSalt(word, salt, false);
    MessageDigest messageDigest = MessageDigest.getInstance("SHA");
    byte[] digest = messageDigest.digest(saltedPass.getBytes());
    return new String(Hex.encodeHex(digest));
}

From source file:com.olayinka.file.transfer.Utils.java

public static String hash(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = null;/*from www.jav a 2 s .c om*/
    md = MessageDigest.getInstance("SHA-256");
    md.update(string.getBytes());
    byte[] digest = md.digest();
    return String.valueOf(Hex.encodeHex(digest));
}

From source file:gov.nih.nci.cagrid.opensaml.provider.SecureRandomIDProvider.java

/**
 * @see gov.nih.nci.cagrid.opensaml.SAMLIdentifier#getIdentifier()
 *//*from ww  w .j  a va 2 s . co m*/
public synchronized String getIdentifier() throws SAMLException {
    byte[] buf = new byte[16];
    random.nextBytes(buf);
    return "_".concat(new String(Hex.encodeHex(buf)));
}

From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java

/**
 * Encrypts a byte[]./*ww  w .  ja  va 2s .co m*/
 *
 * @param c   The byte[] to encrypt.
 * @param key The key.
 * @return The encrypted array as a HEX string.
 */
public static String encrypt(byte[] c, String key) {
    try {
        SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encoded = cipher.doFinal(c);
        return new String(Hex.encodeHex(encoded));

    } catch (Exception e) {
        logger.warn("Could not encrypt byte[]", e);
        return null;
    }
}

From source file:com.zimbra.cs.octosync.PatchRef.java

public String toString() {
    return "fileId: " + fileId + ", fileVersion: " + fileVersion + ", offset: " + offset + ", length: " + length
            + ", hash: " + new String(Hex.encodeHex(hashKey));
}

From source file:edu.internet2.middleware.openid.common.impl.RandomIdentifierGenerator.java

/** {@inheritDoc} */
public String generateIdentifier(int size) {
    byte[] buf = new byte[size];
    random.nextBytes(buf);/*from w  ww  .  j  a  v a2s . com*/
    return "_".concat(new String(Hex.encodeHex(buf)));
}

From source file:com.agiletec.plugins.jpuserreg.aps.system.services.userreg.util.ShaEncoder.java

public static String encodePassword(String password, String salt) throws NoSuchAlgorithmException {

    String saltedPass = mergePasswordAndSalt(password, salt, false);

    MessageDigest messageDigest = MessageDigest.getInstance("SHA");

    byte[] digest = messageDigest.digest(saltedPass.getBytes());

    return new String(Hex.encodeHex(digest));

}

From source file:be.fedict.hsm.ws.impl.NamePasswordCallbackHandler.java

public NamePasswordCallbackHandler(byte[] encodedCertificate) {
    this.name = DigestUtils.sha1Hex(encodedCertificate);
    this.password = Hex.encodeHex(encodedCertificate);
}

From source file:com.zimbra.cs.account.PreAuthKey.java

private static String getHmac(String data, byte[] key) {
    try {//from w  ww. ja v a  2 s.co m
        ByteKey bk = new ByteKey(key);
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(bk);
        return new String(Hex.encodeHex(mac.doFinal(data.getBytes())));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("fatal error", e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException("fatal error", e);
    }
}

From source file:com.c77.androidstreamingclient.lib.video.DumpDecoder.java

@Override
public void decodeFrame(BufferedSample frame) {
    String debugging = "Size = " + frame.getSampleSize();
    debugging += " [" + new String(Hex.encodeHex(Arrays.copyOf(frame.getBuffer().array(), 16))) + "]";
    Log.i("DumpDecoder", debugging);
}