List of usage examples for com.google.common.hash Hashing md5
public static HashFunction md5()
From source file:com.cinchapi.concourse.server.http.HttpRequests.java
/** * Return an MD5 hash that represents the fingerprint (ip address and * browser information) for the client.//from w w w .ja va 2s .co m * * @param request * @return the client fingerprint */ public static String getFingerprint(HttpRequest request) { StringBuilder sb = new StringBuilder(); sb.append(getUserAgent(request)); sb.append(getIpAddress(request)); return Hashing.md5().hashUnencodedChars(sb).toString(); }
From source file:com.dssmp.agent.tailing.KinesisRecord.java
@VisibleForTesting String generatePartitionKey(PartitionKeyOption option) { Preconditions.checkNotNull(option);/*from w w w . j av a 2 s . c om*/ if (option == PartitionKeyOption.DETERMINISTIC) { Hasher hasher = Hashing.md5().newHasher(); hasher.putBytes(data.array()); return hasher.hash().toString(); } if (option == PartitionKeyOption.RANDOM) return "" + ThreadLocalRandom.current().nextDouble(1000000); return null; }
From source file:org.apache.james.user.jpa.model.JPAUser.java
@SuppressWarnings("deprecation") private static HashFunction chooseHashing(String algorithm) { switch (algorithm) { case "MD5": return Hashing.md5(); case "SHA-256": return Hashing.sha256(); case "SHA-512": return Hashing.sha512(); default://from w w w .j a v a2 s . c o m return Hashing.sha1(); } }
From source file:com.github.vatbub.tictactoe.common.OnlineMultiplayerRequestOpponentRequest.java
public String getRequestId() { return Hashing.md5().newHasher() .putString(getClientIdentifier() + getDesiredOpponentIdentifier() + getSalt(), Charsets.UTF_8) .hash().toString();// w ww. j a v a 2 s . c om }
From source file:ph.samson.maven.enforcer.rule.checksum.FileChecksum.java
@Override public void execute(EnforcerRuleHelper erh) throws EnforcerRuleException { if (file == null || !file.canRead()) { throw new EnforcerRuleException("Missing file: " + file); }/*from w w w . j a v a 2 s . co m*/ HashFunction hashFn; switch (type) { case "crc32": hashFn = Hashing.crc32(); break; case "crc32c": hashFn = Hashing.crc32c(); break; case "md5": hashFn = Hashing.md5(); break; case "sha1": hashFn = Hashing.sha1(); break; case "sha256": hashFn = Hashing.sha256(); break; case "sha512": hashFn = Hashing.sha512(); break; default: throw new EnforcerRuleException("Unsupported hash type: " + type); } String hash; try { hash = hashFn.hashBytes(Files.readAllBytes(file.toPath())).toString(); } catch (IOException ex) { throw new EnforcerRuleException("Failed reading " + file, ex); } if (!hash.equalsIgnoreCase(checksum)) { throw new EnforcerRuleException( type + " hash of " + file + " was " + hash + " but expected " + checksum); } }
From source file:com.google.gerrit.server.change.GetRevisionActions.java
@Override public String getETag(RevisionResource rsrc) { Hasher h = Hashing.md5().newHasher(); CurrentUser user = rsrc.getControl().getUser(); try {//from w w w.j a va2 s . c o m rsrc.getChangeResource().prepareETag(h, user); h.putBoolean(Submit.wholeTopicEnabled(config)); ReviewDb db = dbProvider.get(); ChangeSet cs = mergeSuperSet.get().completeChangeSet(db, rsrc.getChange(), user); for (ChangeData cd : cs.changes()) { changeResourceFactory.create(cd.changeControl()).prepareETag(h, user); } h.putBoolean(cs.furtherHiddenChanges()); } catch (IOException | OrmException e) { throw new OrmRuntimeException(e); } return h.hash().toString(); }
From source file:org.lenskit.data.store.BareEntityCollection.java
BareEntityCollection(EntityType et, LongSortedArraySet ids) {
entityType = et;
idSet = ids;
Hasher hash = Hashing.md5().newHasher();
idSet.forEach((LongConsumer) hash::putLong);
contentHash = hash.hash();
}
From source file:net.yoomai.wechat.utils.StringUtils.java
/** * ????//from www. j a v a 2 s .co m * * @param params ?ASCII ???? * @param encrypt ? SHA1 MD5 * @return */ public static String signature(Map params, String encrypt, boolean toUpperCase) { String sign = ""; // ? String buffer = generateQueryString(params, true); // log.debug(" => {}", buffer.toString()); if ("MD5".equals(encrypt)) { // MD5 sign = Hashing.md5().hashString(buffer, Charsets.UTF_8).toString(); } else if ("SHA1".equals(encrypt)) { // SHA1 sign = Hashing.sha1().hashString(buffer, Charsets.UTF_8).toString(); } // log.debug("? <=> {}", sign); if (toUpperCase) { sign = sign.toUpperCase(); } return sign; }
From source file:com.netflix.priam.utils.SystemUtils.java
/** * Get a Md5 string which is similar to OS Md5sum *///ww w .ja v a 2s . c o m public static String md5(File file) { try { HashCode hc = Files.hash(file, Hashing.md5()); return toHex(hc.asBytes()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.xebialabs.overtherepy.DirectoryDiff.java
/** * Calculate an MD5 hash for the given file. * * @param file for which MD5 should be calculated. * @return MD5 hash//from ww w.j av a 2s.c o m * @throws IOException */ public static String md5(final OverthereFile file) throws IOException { File sourceFile = new File(file.getPath()); ByteSource source = Files.asByteSource(sourceFile); return source.hash(Hashing.md5()).toString(); }