Example usage for com.google.common.hash Hashing sha1

List of usage examples for com.google.common.hash Hashing sha1

Introduction

In this page you can find the example usage for com.google.common.hash Hashing sha1.

Prototype

public static HashFunction sha1() 

Source Link

Document

Returns a hash function implementing the SHA-1 algorithm (160 hash bits) by delegating to the SHA-1 MessageDigest .

Usage

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:org.liquigraph.model.Checksums.java

public static String checksum(Collection<String> queries) {
    Hasher hasher = Hashing.sha1().newHasher();
    for (String query : queries) {
        hasher = hasher.putString(query, Charsets.UTF_8);
    }/*from   w  w  w.  j a va  2s. c o m*/
    return hasher.hash().toString();
}

From source file:com.google.collide.server.shared.util.FileHasher.java

public static ByteString getSha1(String contents) {
    Stopwatch stopWatch = new Stopwatch().start();
    ByteString sha1 = ByteString.copyFrom(Hashing.sha1().hashString(contents).asBytes());
    return sha1;/*  w  w w  . j  a  v  a  2  s.  c om*/
}

From source file:io.blobkeeper.common.util.TokenUtils.java

@NotNull
public static String getToken(String secretToken, long identity) {
    return Hashing.sha1().hashString(secretToken + identity, Charset.forName("UTF-8")).toString();
}

From source file:org.fenixedu.academic.util.FenixDigestUtils.java

public static String createDigest(String data) {
    return Hashing.sha1().hashString(data, Charsets.UTF_8).toString();
}

From source file:org.glowroot.config.Versions.java

public static String getVersion(Object obj) {
    try {//from   w ww.j a v a  2s  .  c om
        return Hashing.sha1().hashString(mapper.writeValueAsString(obj), Charsets.UTF_8).toString();
    } catch (JsonProcessingException e) {
        logger.error(e.getMessage(), e);
        return "0000000000000000000000000000000000000000";
    }
}

From source file:com.lithium.flow.util.HashFunctions.java

@Nonnull
public static HashFunction of(@Nonnull String name) {
    checkNotNull(name);//from   ww  w  .  ja  v a 2 s.  c  o  m
    switch (name) {
    case "adler32":
        return Hashing.adler32();
    case "crc32":
        return Hashing.crc32();
    case "md5":
        return Hashing.md5();
    case "sha1":
        return Hashing.sha1();
    case "sha256":
        return Hashing.sha256();
    case "sha512":
        return Hashing.sha512();
    case "sipHash24":
        return Hashing.sipHash24();
    case "murmur3_32":
        return Hashing.murmur3_32();
    case "murmur3_128":
        return Hashing.murmur3_128();
    default:
        throw new RuntimeException("unknown hash: " + name);
    }
}

From source file:org.glowroot.common.util.Versions.java

public static String getJsonVersion(Object obj) {
    try {//w w  w .  java  2 s.c o  m
        return Hashing.sha1().hashString(mapper.writeValueAsString(obj), UTF_8).toString();
    } catch (JsonProcessingException e) {
        logger.error(e.getMessage(), e);
        return "0000000000000000000000000000000000000000";
    }
}

From source file:com.google.devtools.build.lib.remote.ContentDigests.java

public static ContentDigest computeDigest(byte[] blob) {
    return buildDigest(Hashing.sha1().hashBytes(blob).asBytes(), blob.length);
}

From source file:com.facebook.buck.distributed.BuckVersionUtil.java

public static BuckVersion createFromLocalBinary(Path localBuckBinary) throws IOException {
    byte[] data = Files.readAllBytes(localBuckBinary);
    String hash = Hashing.sha1().newHasher().putBytes(data).hash().toString();

    FileInfo buckBinary = new FileInfo();
    buckBinary.setContent(data);/* w w  w .  j av a2 s  .c o  m*/
    buckBinary.setContentHash(hash);

    BuckVersion buckVersion = new BuckVersion();
    buckVersion.setType(BuckVersionType.DEVELOPMENT);
    buckVersion.setDevelopmentVersion(buckBinary);
    return buckVersion;
}