Example usage for com.google.common.hash HashCode toString

List of usage examples for com.google.common.hash HashCode toString

Introduction

In this page you can find the example usage for com.google.common.hash HashCode toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string containing each byte of #asBytes , in order, as a two-digit unsigned hexadecimal number in lower case.

Usage

From source file:com.taobao.tanggong.HashUtil.java

public static String md5Hash(String src) {
    HashFunction hf = Hashing.md5();/*  w  w  w. j a va 2 s.co  m*/
    HashCode hc = hf.newHasher().putString(src).hash();
    return hc.toString();
}

From source file:library.ScratchSpace.java

public static String createLicenseKey(String userName, String email, String action) {
    final String s = userName + "|" + email + "|" + action;
    final HashFunction hashFunction = Hashing.sha1();
    final HashCode hashCode = hashFunction.hashString(s);
    final String upper = hashCode.toString().toUpperCase();
    return group(upper);
}

From source file:brooklyn.rest.security.PasswordHasher.java

public static String sha256(String salt, String password) {
    byte[] salted = Charsets.UTF_8.encode((salt == null ? "" : salt) + password).array();
    HashCode hash = Hashing.sha256().hashBytes(salted);
    return hash.toString();
}

From source file:org.apache.brooklyn.rest.security.PasswordHasher.java

public static String sha256(String salt, String password) {
    if (salt == null)
        salt = "";
    byte[] bytes = (salt + password).getBytes(Charsets.UTF_8);
    HashCode hash = Hashing.sha256().hashBytes(bytes);
    return hash.toString();
}

From source file:com.addthis.hydra.common.hash.MD5HashFunction.java

public static String hashAsString(byte[] bytes) {
    HashCode hc = Hashing.md5().hashBytes(bytes);
    return hc.toString();
}

From source file:com.addthis.hydra.common.hash.MD5HashFunction.java

public static String hashAsString(String key) {
    HashCode hc = Hashing.md5().hashUnencodedChars(key);
    return hc.toString();
}

From source file:com.google.collide.dtogen.DtoGenerator.java

private static String getApiHash(File interfaceJar) throws IOException {
    byte[] fileBytes = Files.toByteArray(interfaceJar);
    HashCode hashCode = Hashing.sha1().hashBytes(fileBytes);
    return hashCode.toString();
}

From source file:edu.cmu.lti.oaqa.ecd.phase.ProcessingStepUtils.java

/**
 * Execution hash is computed from JCas currentExperimentId, trace and sequenceId
 * @return MD5 hash corresponding to the above mentioned elements
 *///from   ww w .  j  a  va2  s.  c o  m
public static String getExecutionIdHash(String experimentId, Trace trace, String sequenceId) {
    HashFunction hf = Hashing.md5();
    Hasher hasher = hf.newHasher();
    hasher.putString(experimentId, StandardCharsets.UTF_8);
    hasher.putString(trace.getTrace(), StandardCharsets.UTF_8);
    hasher.putString(String.valueOf(sequenceId), StandardCharsets.UTF_8);
    HashCode hash = hasher.hash();
    final String traceHash = hash.toString();
    return traceHash;
}

From source file:edu.cmu.lti.oaqa.ecd.phase.ProcessingStepUtils.java

/**
 * Execution hash is computed from JCas currentExperimentId, trace and sequenceId
 * @return MD5 hash corresponding to the above mentioned elements
 *///from   w  ww  . jav  a 2  s . c om
public static String getExecutionIdHash(JCas jcas) {
    String experimentId = ProcessingStepUtils.getCurrentExperimentId(jcas);
    Trace trace = ProcessingStepUtils.getTrace(jcas);
    String sequenceId = ProcessingStepUtils.getSequenceId(jcas);
    HashFunction hf = Hashing.md5();
    Hasher hasher = hf.newHasher();
    hasher.putString(experimentId, StandardCharsets.UTF_16LE);
    hasher.putString(trace.getTrace(), StandardCharsets.UTF_16LE);
    hasher.putString(String.valueOf(sequenceId), StandardCharsets.UTF_16LE);
    HashCode hash = hasher.hash();
    final String traceHash = hash.toString();
    return traceHash;
}

From source file:org.metaservice.core.file.FileUriUtils.java

public static FileIdentifier storeFile(InputStream inputStream) throws FileProcessingException {

    try {/*from w  ww .ja  va  2 s  .  c  o  m*/
        File localDir = com.google.common.io.Files.createTempDir();
        File localFile = new File(localDir.toString() + "/x");
        IOUtils.copy(inputStream, new FileOutputStream(localFile));
        HashCode x = com.google.common.io.Files.hash(localFile, Hashing.sha1());
        long size = localFile.length();
        Path target = getFile(x.toString(), size);
        Files.createDirectories(target.getParent());
        Files.move(localFile.toPath(), target);
        return new FileIdentifier(x.toString(), size);
    } catch (IOException e) {
        throw new FileProcessingException(e);
    }
}