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

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

Introduction

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

Prototype

public static String encodeHexString(byte[] data) 

Source Link

Document

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

Usage

From source file:com.lhings.java.utils.ByteMan.java

public static String byteArrayToHexString(byte[] m) {
    return Hex.encodeHexString(m);
}

From source file:io.moquette.spi.impl.DebugUtils.java

public static String payload2Str(byte[] content) {
    boolean notPrintAble = intStream(content).filter(DebugUtils::isNotPrintableAscii).findAny().isPresent();

    if (notPrintAble)
        return "0x" + Hex.encodeHexString(content);

    return new String(content);
}

From source file:de.pawlidi.openaletheia.utils.Converter.java

public static String hexToString(byte[] data) {
    return Hex.encodeHexString(data);
}

From source file:com.apabi.r2k.common.security.util.NonceUtils.java

/**
 * SecureRandom?, Hex?.// w  w  w  . j  a v a 2 s . c o  m
 * 
 * @param length ,?.
 */
public static String randomHexString(final int length) {
    SecureRandom nonceGenerator = new SecureRandom();
    byte[] nonce = new byte[length / 2];
    nonceGenerator.nextBytes(nonce);
    return Hex.encodeHexString(nonce);
}

From source file:com.platform.common.utils.security.NonceUtils.java

/**
 * SecureRandom?, Hex?./*from   www  .  j av a  2s  .c  o  m*/
 * 
 * @param length ,?.
 */
public static String randomHexString(int length) {
    SecureRandom nonceGenerator = new SecureRandom();
    byte[] nonce = new byte[length / 2];
    nonceGenerator.nextBytes(nonce);
    return Hex.encodeHexString(nonce);
}

From source file:com.linkedin.pinot.common.utils.primitive.ByteArray.java

/**
 * Static utility function to convert a byte[] to Hex string.
 *
 * @param bytes byte[] to convert//from  w ww .j  a  v a2 s  .c om
 * @return Equivalent Hex String.
 */
public static String toHexString(byte[] bytes) {
    return Hex.encodeHexString(bytes);
}

From source file:com.tydic.dbp.utils.ThreeDesUtils.java

public static String encryptMode(String Src) {
    try {// ww  w .  j a v  a2 s .  c  o  m
        // ?
        SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm);
        // 
        Cipher c1 = Cipher.getInstance(Algorithm);
        c1.init(Cipher.ENCRYPT_MODE, deskey);
        return Hex.encodeHexString(c1.doFinal(Src.getBytes()));
    } catch (java.security.NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (javax.crypto.NoSuchPaddingException e2) {
        e2.printStackTrace();
    } catch (java.lang.Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

From source file:it.infn.mw.iam.util.ssh.RSAPublicKeyUtils.java

private static String buildMD5Fingerprint(String key) throws InvalidSshKeyException {

    String fingerprint = null;/*from w  ww  . ja v a 2 s  . c  om*/

    try {

        byte[] decodedKey = Base64.getDecoder().decode(key);
        byte[] digest = MessageDigest.getInstance(MessageDigestAlgorithms.MD5).digest(decodedKey);
        fingerprint = Hex.encodeHexString(digest);

    } catch (Exception e) {

        throw new InvalidSshKeyException("Error during fingerprint generation: RSA key is not base64 encoded",
                e);
    }

    return fingerprint;
}

From source file:fi.ilmoeuro.membertrack.util.Crypto.java

public static String hash(String candidate, String salt) {
    try {//from  w  ww  . j  a v  a  2s.co m
        SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        KeySpec ks = new PBEKeySpec(candidate.toCharArray(), salt.getBytes(StandardCharsets.US_ASCII), 1024,
                128);
        SecretKey sk = skf.generateSecret(ks);
        Key k = new SecretKeySpec(sk.getEncoded(), "AES");
        return Hex.encodeHexString(k.getEncoded());
    } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
        throw new RuntimeException("Error while hashing", ex);
    }
}

From source file:fr.cph.stock.security.Security.java

/**
 * Encode to sha256 the user password/*from  w  w  w .j a v  a 2s .  com*/
 * 
 * @param str
 *            the password to encode
 * @return an encoded string
 * @throws NoSuchAlgorithmException
 *             the NoSuchAlgorithmException
 * @throws UnsupportedEncodingException
 *             the UnsupportedEncodingException
 */
public static String encodeToSha256(final String str)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    byte[] hash = digest.digest(str.getBytes("UTF-8"));
    String encoded = Hex.encodeHexString(hash);
    return encoded;
}