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:co.edu.uniandes.csw.Arquidalgos.usuario.service.UsuarioService.java

@POST
@Path("/agregarAmigos")
public List<UsuarioDTO> agregarAmigos(UsuarioAmigosDTO usuarioAmigos) throws Exception {

    Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
    String key = "123";
    SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(), "HmacSHA256");
    sha256_HMAC.init(secret_key);/* w w w. ja v  a2  s  .c  o m*/

    String x = usuarioAmigos.toString();
    System.out.println("TO String: " + x);

    String hash = Hex.encodeHexString(sha256_HMAC.doFinal(x.getBytes()));
    System.out.println("CODIGO HASH: " + hash);
    System.out.println("CODIGO HASH JSON " + usuarioAmigos.getHash());

    boolean alterado = !(hash.equalsIgnoreCase(usuarioAmigos.getHash()));
    System.out.println("Alterado: " + alterado);

    if (alterado) {
        System.out.println("Alterado el sistema");
    }
    return this.usuarioLogicService.agregarAmigos(usuarioAmigos);
}

From source file:com.wavemaker.tools.cloudfoundry.spinup.authentication.SharedSecretPropagation.java

/**
 * Send the specified shared secret to a running cloud foundry application.
 * //from   ww w  .  j  ava  2 s  . c om
 * @param client client
 * @param secret the secret to send
 * @param application the application to send the secret to
 */
public void sendTo(CloudFoundryClient client, SharedSecret secret, CloudApplication application)
        throws CloudFoundryException {
    Assert.notNull(client, "Client must not be null");
    Assert.notNull(application, "Application must not be null");
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Propagating shared secret to " + application.getName());
    }
    Map<String, String> env = new HashMap<String, String>();
    env.putAll(application.getEnvAsMap());
    String envValue = Hex.encodeHexString(secret.getBytes());
    if (!envValue.equals(env.get(ENV_KEY))) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Restarting " + application.getName() + " due to new shared secret");
        }
        env.put(ENV_KEY, envValue);
        client.updateApplicationEnv(application.getName(), env);
        client.restartApplication(application.getName());
    }
}

From source file:com.bitbreeds.webrtc.dtls.DtlsMuxStunTransport.java

public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException {
    socket.setSoTimeout(waitMillis);/*ww  w  . j  a  v  a  2 s . co m*/
    DatagramPacket packet = new DatagramPacket(buf, off, len);
    socket.receive(packet);
    logger.trace("Socket read msg: {}",
            Hex.encodeHexString(SignalUtil.copyRange(buf, new ByteRange(0, packet.getLength()))));
    if (buf.length >= 2 && buf[0] == 0 && buf[1] == 1) {
        SocketAddress currentSender = packet.getSocketAddress();

        byte[] data = Arrays.copyOf(packet.getData(), packet.getLength());

        byte[] out = bindingService.processBindingRequest(data, parent.getLocal().getUserName(),
                parent.getLocal().getPassword(), (InetSocketAddress) currentSender);

        logger.trace("Stun packet received, responding with {}", Hex.encodeHexString(out));
        this.send(out, 0, out.length);
        return 0; //We do not want DTLS to process (not that it will anyway), so we return 0 here.
    }

    return packet.getLength();
}

From source file:com.buaa.cfs.fs.XAttrCodec.java

/**
 * Encode byte[] value to string representation with encoding. Values encoded as text strings are enclosed in double
 * quotes (\"), while strings encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
 *
 * @param value    byte[] value/*from   w w  w . j av  a2 s . c  om*/
 * @param encoding
 *
 * @return String string representation of value
 *
 * @throws IOException
 */
public static String encodeValue(byte[] value, XAttrCodec encoding) throws IOException {
    Preconditions.checkNotNull(value, "Value can not be null.");
    if (encoding == HEX) {
        return HEX_PREFIX + Hex.encodeHexString(value);
    } else if (encoding == BASE64) {
        return BASE64_PREFIX + base64.encodeToString(value);
    } else {
        return "\"" + new String(value, "utf-8") + "\"";
    }
}

From source file:com.usergrid.count.common.Count.java

/**
 * the counter name should uniquely identify the entity being counted.
 * @return//from w  w  w  . j av  a  2 s .  c  om
 */
@JsonIgnore
public String getCounterName() {
    if (counterName == null) {
        counterName = tableName + ":" + Hex.encodeHexString(getKeyNameBytes().array()) + ":"
                + Hex.encodeHexString(getColumnNameBytes().array());
    }
    return counterName;
}

From source file:com.liferay.portal.util.DigesterImpl.java

public String digestHex(String algorithm, String... text) {
    byte[] bytes = digestRaw(algorithm, text);

    return Hex.encodeHexString(bytes);
}

From source file:com.github.horrorho.inflatabledonkey.data.blob.BlobA0.java

@Override
public String toString() {
    return "BlobA0{" + "type=0x" + Integer.toHexString(type()) + ",length=0x" + Integer.toHexString(length())
            + ", x=" + x + ", iterations=" + iterations + ", y=" + y + ", dsid=0x" + Hex.encodeHexString(dsid())
            + ", salt=0x" + Hex.encodeHexString(salt()) + ", key=0x" + Hex.encodeHexString(key()) + ", data=0x"
            + Hex.encodeHexString(data()) + ", label=" + label + ", timestamp=" + timestamp + '}';
}

From source file:br.com.ingenieux.jenkins.plugins.codecommit.RequestSignerBase.java

protected String hexEncode(String obj) {
    return Hex.encodeHexString(obj.getBytes(DEFAULT_CHARSET));
}

From source file:com.roche.sequencing.bioinformatics.common.utils.Md5CheckSumUtil.java

public static String md5SumWithSkippingCommentLines(IInputStreamFactory inputStreamFactory)
        throws FileNotFoundException, IOException {
    InputStream inputStream;//from ww  w.j  a  v a2 s .  c  o  m
    if (GZipUtil.isCompressed(inputStreamFactory)) {
        inputStream = new GZIPInputStream(inputStreamFactory.createInputStream());
    } else {
        inputStream = new BufferedInputStream(inputStreamFactory.createInputStream());
    }

    MessageDigest md5SumDigest = null;
    try {
        md5SumDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError();
    }

    try {
        byte[] character = new byte[1024];
        StringBuilder currentLine = new StringBuilder();
        int readChars = 0;
        while ((readChars = inputStream.read(character)) != -1) {
            for (int i = 0; i < readChars; ++i) {
                char currentCharacter = (char) character[i];
                if (currentCharacter == StringUtil.NEWLINE_SYMBOL) {
                    currentLine.append(currentCharacter);
                    String line = currentLine.toString();
                    if (!line.startsWith("#")) {
                        md5SumDigest.update(line.getBytes());
                    }

                    currentLine = new StringBuilder();

                } else {
                    currentLine.append(currentCharacter);
                }
            }
        }
    } finally {
        inputStream.close();
    }
    String md5Sum = Hex.encodeHexString(md5SumDigest.digest());
    return md5Sum;
}

From source file:com.lightboxtechnologies.nsrl.HashRecordProcessorTest.java

@Test(expected = BadDataException.class)
public void processNegativeProdCode() throws BadDataException {
    final RecordProcessor<HashData> proc = new HashRecordProcessor();
    proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32),
            name, String.valueOf(size), "-1", os_code, special_code });
}