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

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

Introduction

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

Prototype

public static HashFunction md5() 

Source Link

Document

Returns a hash function implementing the MD5 hash algorithm (128 hash bits) by delegating to the MD5 MessageDigest .

Usage

From source file:com.opera.core.systems.common.hash.MD5.java

/**
 * Get the MD5 hash of the given byte array.
 *
 * @param bytes a byte array// w  w w .jav a2s  .  c  om
 * @return a byte array of the MD5 hash
 * @throws java.io.IOException if an I/O error occurs
 */
public static byte[] hash(byte[] bytes) throws IOException {
    return Hashing.md5().hashBytes(bytes).asBytes();
}

From source file:utils.HashGenerator.java

/**
 * Return file's MD5./*w  ww  .j ava  2s .c  om*/
 * @param filePath the path where the file to have the md5 generated belongs.
 * @return The MD55 in String
 * @throws NoSuchAlgorithmException
 * @throws IOException
 */
public static String generateMD5(String filePath) throws NoSuchAlgorithmException, IOException {
    File file = new File(filePath);
    String md5 = BaseEncoding.base16().encode(Files.hash(file, Hashing.md5()).asBytes()).toLowerCase();
    return md5;
}

From source file:com.github.luluvise.droid_utils.lib.HashUtils.java

/**
 * Gets a String hash generated using the MD5 hashing algorithm with the
 * passed strings as input.//from w  w  w  . j a  va 2s.  c  o m
 */
public static String getMD5Hash(@Nonnull String... strings) {
    return getHash(Hashing.md5(), strings);
}

From source file:com.github.marcosalis.kraken.utils.HashUtils.java

/**
 * Gets a String hash generated using the MD5 hashing algorithm with the
 * passed strings as input.//ww w . j a v a2 s .com
 */
@Nonnull
public static String getMD5Hash(@Nonnull String... strings) {
    return getHash(Hashing.md5(), strings);
}

From source file:jp.classmethod.aws.gradle.s3.SyncTask.java

private static String md5(File file) {
    try {/*  w  w  w.j  av a  2 s .c o  m*/
        return Files.hash(file, Hashing.md5()).toString();
    } catch (IOException e) {
        return "";
    }
}

From source file:com.zxy.commons.codec.utils.MD5Utils.java

/**
 * 32?md5?//from   w w  w.  jav a2  s .  co  m
 * 
 * @param source source
 * @return 32?md5?
*/
public static String encode32(String source) {
    if (StringUtils.isBlank(source)) {
        return source;
    }
    return Hashing.md5().hashBytes(source.getBytes()).toString();
}

From source file:com.zxy.commons.lang.idgenerator.IdUtils.java

/**
 * ?id/*  www  . j  a  va2 s  . c  om*/
 * <p>
 * ?uuid?md5???16?
 * 
 * @return id
 */
public static String genStringId() {
    String uuid = UUIDUtils.newUUID();
    String md5 = Hashing.md5().hashBytes(uuid.getBytes()).toString().substring(8, 24);
    if (md5.length() > ID_LENGTH) {
        md5 = md5.substring(0, ID_LENGTH);
    }
    return md5;
}

From source file:com.gamejolt.util.Checksum.java

public String md5(byte[] data) {
    return Hashing.md5().hashBytes(data).toString();
}

From source file:com.opera.core.systems.common.hash.MD5.java

/**
 * Get the MD5 hash of the given file.// w  w w . j  a v a 2 s.c om
 *
 * @param file file to compute a hash on
 * @return a byte array of the MD5 hash
 * @throws IOException              if file cannot be found
 */
public static byte[] hash(File file) throws IOException {
    return Files.hash(file, Hashing.md5()).asBytes();
}

From source file:com.dangdang.ddframe.job.lite.internal.reg.RegistryCenterFactory.java

/**
 * .//w  ww .  ja  v a  2s  .c o  m
 *
 * @param connectString 
 * @param namespace ??
 * @param digest ?
 * @return 
 */
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString,
        final String namespace, final Optional<String> digest) {
    Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace,
            Charsets.UTF_8);
    if (digest.isPresent()) {
        hasher.putString(digest.get(), Charsets.UTF_8);
    }
    HashCode hashCode = hasher.hash();
    if (regCenterMap.containsKey(hashCode)) {
        return regCenterMap.get(hashCode);
    }
    ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
    if (digest.isPresent()) {
        zkConfig.setDigest(digest.get());
    }
    CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
    result.init();
    regCenterMap.putIfAbsent(hashCode, result);
    return result;
}