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:de.phoenix.util.hash.SHA1Hasher.java

public String generate(InputStream binaryStream) {

    try {//from   w ww.jav a  2 s. c o m
        MessageDigest ms = MessageDigest.getInstance(ALGORITHM);
        for (int read = 0; (read = binaryStream.read(buffer)) != -1;) {
            ms.update(buffer, 0, read);
        }
        return Hex.encodeHexString(ms.digest());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:monasca.api.infrastructure.persistence.vertica.MetricQueries.java

static String createDefDimIdInClause(Set<byte[]> defDimIdSet) {

    StringBuilder sb = new StringBuilder("IN ");

    sb.append("(");

    boolean first = true;
    for (byte[] defDimId : defDimIdSet) {

        if (first) {
            first = false;/*from  w  w w  .j a  v a2  s .c o  m*/
        } else {
            sb.append(",");
        }

        sb.append("'" + Hex.encodeHexString(defDimId) + "'");
    }

    sb.append(") ");

    return sb.toString();
}

From source file:io.fluo.webindex.data.fluo.UriCountExport.java

public static String revEncodeLong(Long num) {
    Lexicoder<Long> lexicoder = new ReverseLexicoder<>(new ULongLexicoder());
    return Hex.encodeHexString(lexicoder.encode(num));
}

From source file:com.google.code.commons.checksum.binary.TestBinaryUtils.java

@Test
public void encodeHexString() {
    Assert.assertEquals(Hex.encodeHexString(HELLO_WORLD_BYTE_ARRAY),
            BinaryUtils.encodeHexString(HELLO_WORLD_BYTE_ARRAY));
}

From source file:monasca.persister.repository.Sha1HashId.java

public String toHexString() {
    return Hex.encodeHexString(sha1Hash);
}

From source file:com.yukthi.utils.CryptoUtils.java

/**
 * Encrypts the provided input and convert encrypted bytes into hex string
 * @param secretKey Secret key to use for encryption
 * @param input Input to be encrypted/*  w  w w .  j  a  v  a 2  s.com*/
 * @return encrypted and hex converted string
 */
public static String encrypt(String secretKey, String input) {
    if (secretKey.length() != 16) {
        throw new InvalidArgumentException("Secret key should be of length 16. Specified secrey key length - ",
                secretKey.length());
    }

    //convert input into bytes
    byte inputBytes[] = input.getBytes();

    //encrypt bytes
    byte encryptedBytes[] = doCrypto(Cipher.ENCRYPT_MODE, secretKey, inputBytes);

    //convert encrypted bytes into hex string
    return Hex.encodeHexString(encryptedBytes);
}

From source file:com.alu.e3.prov.lifecycle.IDHelper.java

public static String encode(String original) {
    return Hex.encodeHexString(original.getBytes());
}

From source file:com.jaeksoft.searchlib.util.NetworksUtils.java

public static final String getHardwareAddress(NetworkInterface networkInterface) throws SocketException {
    if (networkInterface == null)
        return null;
    if (networkInterface.getHardwareAddress() == null)
        return null;
    return Hex.encodeHexString(networkInterface.getHardwareAddress());
}

From source file:com.vmware.identity.rest.core.util.RequestSigner.java

/**
 * Signs a string using the private key and SHA 256 with RSA signing algorithm, and
 * returns it as a hex-encoded string.//from  w w  w .ja va2 s  .  c  o m
 *
 * @param signingString the string to sign.
 * @param privateKey the private key to sign the string with.
 * @return the signed string in a hex-encoded format.
 * @throws InvalidKeyException if the key is invalid.
 * @throws SignatureException if the signature algorithm is unable to process the input
 * data provided.
 */
public static String sign(String signingString, PrivateKey privateKey)
        throws InvalidKeyException, SignatureException {
    byte[] bytes = signingString.getBytes(StandardCharsets.UTF_8);

    Signature sig;

    try {
        sig = Signature.getInstance(SHA256_WITH_RSA);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("An error occurred while getting the signature algorithm", e);
    }

    sig.initSign(privateKey);
    sig.update(bytes);

    return Hex.encodeHexString(sig.sign());
}

From source file:com.ait.tooling.server.core.security.SimpleCryptoKeysGenerator.java

@Override
public String getRandomSalt() {
    return Hex.encodeHexString(Tools.randomBytes(32));
}