List of usage examples for com.google.common.hash Hasher putBytes
@Override
Hasher putBytes(byte[] bytes);
From source file:org.gradle.api.internal.hash.DefaultFileHasher.java
private static Hasher createFileHasher() { Hasher hasher = Hashing.md5().newHasher(); hasher.putBytes(SIGNATURE); return hasher; }
From source file:com.facebook.buck.hashing.StringHashing.java
/** * Encodes the string in UTF-8, then hashes the length of the encoded * UTF-8 bytes followed by the bytes themselves. * * Useful to ensure hash codes are different when multiple strings * are hashed in order ("foo" then "bar" should hash differently from "foobar"). */// ww w .j a va 2s. c o m public static void hashStringAndLength(Hasher hasher, String string) { byte[] utf8Bytes = string.getBytes(StandardCharsets.UTF_8); hasher.putInt(utf8Bytes.length); hasher.putBytes(utf8Bytes); }
From source file:org.locationtech.geogig.repository.IndexInfo.java
public static ObjectId getIndexId(String treeName, String attributeName) { final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher(); hasher.putBytes(treeName.getBytes(Charsets.UTF_8)); hasher.putBytes(attributeName.getBytes(Charsets.UTF_8)); return ObjectId.createNoClone(hasher.hash().asBytes()); }
From source file:com.google.devtools.build.lib.worker.WorkerFilesHash.java
public static HashCode getWorkerFilesHash(Iterable<? extends ActionInput> toolFiles, ActionExecutionContext actionExecutionContext) throws IOException { Hasher hasher = Hashing.sha256().newHasher(); for (ActionInput tool : toolFiles) { hasher.putString(tool.getExecPathString(), Charset.defaultCharset()); hasher.putBytes(actionExecutionContext.getActionInputFileCache().getDigest(tool)); }//from w w w . j a v a 2 s . co m return hasher.hash(); }
From source file:org.opendaylight.md.controller.topology.lldp.utils.LLDPDiscoveryUtils.java
/** * @param nodeConnectorId/* w w w . ja v a 2s .c o m*/ * @return extra authenticator for lldp security * @throws NoSuchAlgorithmException */ public static byte[] getValueForLLDPPacketIntegrityEnsuring(final NodeConnectorId nodeConnectorId) throws NoSuchAlgorithmException { final String pureValue = nodeConnectorId + ManagementFactory.getRuntimeMXBean().getName(); final byte[] pureBytes = pureValue.getBytes(); HashFunction hashFunction = Hashing.md5(); Hasher hasher = hashFunction.newHasher(); HashCode hashedValue = hasher.putBytes(pureBytes).hash(); return hashedValue.asBytes(); }
From source file:org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils.java
/** * @param nodeConnectorId// w w w . j av a 2 s . c om * @return extra authenticator for lldp security * @throws NoSuchAlgorithmException */ public static byte[] getValueForLLDPPacketIntegrityEnsuring(final NodeConnectorId nodeConnectorId) throws NoSuchAlgorithmException { String finalKey; if (LLDPActivator.getLldpSecureKey() != null && !LLDPActivator.getLldpSecureKey().isEmpty()) { finalKey = LLDPActivator.getLldpSecureKey(); } else { finalKey = ManagementFactory.getRuntimeMXBean().getName(); } final String pureValue = nodeConnectorId + finalKey; final byte[] pureBytes = pureValue.getBytes(); HashFunction hashFunction = Hashing.md5(); Hasher hasher = hashFunction.newHasher(); HashCode hashedValue = hasher.putBytes(pureBytes).hash(); return hashedValue.asBytes(); }
From source file:com.facebook.buck.parser.cache.impl.Fingerprinter.java
/** * Calculates a strong fingerprint.//from www. j a v a 2 s. c o m * * @param fs the {@link ProjectFilesystem} that we use to calculate the strong fingerprint. * @param includes the list of included build files for which we calculate the strong fingerprint. * @param fileHashCache the {@link FileHashCache} object to use to get the content hash of the * loaded files. * @return a strong fingerprint - {@link HashCode} that represent a unique hash value. * @throws IOException can throw if there is a problem getting the content of the main BUCK build * spec or an included file. */ public static HashCode getStrongFingerprint(ProjectFilesystem fs, ImmutableSortedSet<String> includes, FileHashCache fileHashCache) throws IOException { Hasher hasher = Hashing.sha256().newHasher(); for (String value : includes) { Path value_path = fs.getPath(value); hasher.putString(fs.relativize(value_path).toString(), StandardCharsets.UTF_8); hasher.putBytes(fileHashCache.get(value_path).asBytes()); } return hasher.hash(); }
From source file:com.facebook.buck.rules.Manifest.java
@VisibleForTesting protected static HashCode hashSourcePathGroup(FileHashCache fileHashCache, SourcePathResolver resolver, ImmutableList<SourcePath> paths) throws IOException { if (paths.size() == 1) { return hashSourcePath(paths.asList().get(0), fileHashCache, resolver); }//w ww .j av a2s. c o m Hasher hasher = Hashing.md5().newHasher(); for (SourcePath path : paths) { hasher.putBytes(hashSourcePath(path, fileHashCache, resolver).asBytes()); } return hasher.hash(); }
From source file:com.facebook.buck.core.build.engine.manifest.Manifest.java
/** Hash the files pointed to by the source paths. */ @VisibleForTesting//from ww w . j a va2 s. c o m static HashCode hashSourcePathGroup(FileHashCache fileHashCache, SourcePathResolver resolver, ImmutableList<SourcePath> paths) throws IOException { if (paths.size() == 1) { return hashSourcePath(paths.get(0), fileHashCache, resolver); } Hasher hasher = Hashing.md5().newHasher(); for (SourcePath path : paths) { hasher.putBytes(hashSourcePath(path, fileHashCache, resolver).asBytes()); } return hasher.hash(); }
From source file:com.google.gerrit.server.change.FileContentUtil.java
private static String randSuffix() { // Produce a random suffix that is difficult (or nearly impossible) // for an attacker to guess in advance. This reduces the risk that // an attacker could upload a *.class file and have us send a ZIP // that can be invoked through an applet tag in the victim's browser. ////from ww w .j a v a 2 s. com Hasher h = Hashing.md5().newHasher(); byte[] buf = new byte[8]; NB.encodeInt64(buf, 0, TimeUtil.nowMs()); h.putBytes(buf); rng.nextBytes(buf); h.putBytes(buf); return h.hash().toString(); }