List of usage examples for com.google.common.hash Hasher hash
@CheckReturnValue HashCode hash();
From source file:com.github.mgunlogson.cuckoofilter4j.SerializableSaltedHasher.java
HashCode hashObj(T object) { Hasher hashInst = hasher.newHasher(); hashInst.putObject(object, funnel); hashInst.putLong(seedNSalt); return hashInst.hash(); }
From source file:com.facebook.buck.cxx.LcUuidScrubber.java
@Override public void scrubFile(FileChannel file) throws IOException, ScrubException { if (!Machos.isMacho(file)) { return;// w w w . j a v a2s . c o m } long size = file.size(); MappedByteBuffer map = file.map(FileChannel.MapMode.READ_WRITE, 0, size); try { Machos.setUuid(map, ZERO_UUID); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } map.rewind(); Hasher hasher = Hashing.sha1().newHasher(); while (map.hasRemaining()) { hasher.putByte(map.get()); } map.rewind(); try { Machos.setUuid(map, Arrays.copyOf(hasher.hash().asBytes(), 16)); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } }
From source file:org.ambraproject.service.password.PasswordDigestService.java
private byte[] produceHash(byte[] salt, String plaintextPassword) { byte[] passwordBytes = plaintextPassword.getBytes(BYTE_ENCODING); Hasher hasher = HASH_FUNCTION.newHasher(salt.length + passwordBytes.length); hasher.putBytes(salt);//from ww w . ja v a 2s . com hasher.putBytes(passwordBytes); return hasher.hash().asBytes(); }
From source file:com.facebook.buck.cxx.toolchain.objectfile.LcUuidContentsScrubber.java
@Override public void scrubFile(FileChannel file) throws IOException, ScrubException { if (!Machos.isMacho(file)) { return;//from ww w.j a va 2 s. c o m } long size = file.size(); MappedByteBuffer map = file.map(FileChannel.MapMode.READ_WRITE, 0, size); try { Machos.setUuidIfPresent(map, ZERO_UUID); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } map.rewind(); Hasher hasher = Hashing.sha1().newHasher(); while (map.hasRemaining()) { hasher.putByte(map.get()); } map.rewind(); try { Machos.setUuidIfPresent(map, Arrays.copyOf(hasher.hash().asBytes(), 16)); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } }
From source file:com.tfgridiron.crowdsource.cmdline.ArchiveCreator.java
public String checksumFileCollection(SpreadsheetIndexer spreadsheetIndexer, Set<SpreadsheetMetadata> includedMetadata) { Set<String> allChecksums = new TreeSet<String>(); for (SpreadsheetMetadata m : includedMetadata) { allChecksums.add(m.getChecksum()); }/*from w w w . ja v a 2s . com*/ Hasher hasher = Hashing.sha512().newHasher(); for (String checksum : allChecksums) { hasher.putString(checksum); } return hasher.hash().toString(); }
From source file:org.gradle.api.internal.changedetection.state.JvmClassHasher.java
/** * @return null if the class should not be included in the ABI. *//* w w w.j a va2s . c om*/ @Nullable public HashCode hashClassFile(FileDetails fileDetails) { HashCode signature = persistentCache.get(fileDetails.getContent().getContentMd5()); if (signature != null) { return signature; } File file = new File(fileDetails.getPath()); try { byte[] src = Files.toByteArray(file); Hasher hasher = createHasher(); if (!hashClassBytes(hasher, src)) { return null; } signature = hasher.hash(); } catch (Exception e) { throw new UncheckedIOException("Could not calculate the signature for class file " + file, e); } persistentCache.put(fileDetails.getContent().getContentMd5(), signature); return signature; }
From source file:org.apache.servicecomb.it.edge.encrypt.filter.EdgeSignatureResponseFilter.java
@Override public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) { if (invocation == null) { return;//from w w w. j ava 2s .c o m } EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext() .get(EdgeConst.ENCRYPT_CONTEXT); if (encryptContext == null) { return; } Hcr hcr = encryptContext.getHcr(); // bad practice: it's better to set signature in response header Buffer bodyBuffer = responseEx.getBodyBuffer(); String body = bodyBuffer.toString(); if (body.endsWith("}")) { Hasher hasher = Hashing.sha256().newHasher(); hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8); hasher.putString(body, StandardCharsets.UTF_8); String signature = hasher.hash().toString(); LOGGER.info("beforeSendResponse signature: {}", signature); body = body.substring(0, body.length() - 1) + ",\"signature\":\"" + signature + "\"}"; responseEx.setBodyBuffer(Buffer.buffer(body)); } }
From source file:com.ibm.vicos.common.crypto.CryptoUtils.java
public String hash(final Iterable<? extends Serializable> of) { checkNotNull(of, "of"); if (Iterators.size(of.iterator()) > 0) { Hasher hasher = getHashFunction().newHasher(); for (Object obj : of) { hasher.putString(obj.toString(), Charsets.UTF_8); }/* w w w .j av a2s . c o m*/ return hasher.hash().toString(); } else { return NULL_HASH; } }
From source file:com.github.mgunlogson.cuckoofilter4j.SerializableSaltedHasher.java
/** * hashes the object with an additional salt. For purpose of the cuckoo * filter, this is used when the hash generated for an item is all zeros. * All zeros is the same as an empty bucket, so obviously it's not a valid * tag. // w ww.j av a2s . c o m */ HashCode hashObjWithSalt(T object, int moreSalt) { Hasher hashInst = hasher.newHasher(); hashInst.putObject(object, funnel); hashInst.putLong(seedNSalt); hashInst.putInt(moreSalt); return hashInst.hash(); }
From source file:mx.itam.metodos.lshclustering.MinhashEmitMapper.java
@Override public void map(Text id, IntArrayWritable values, Context context) throws IOException, InterruptedException { for (int i = 0; i < functionsCount; i++) { hashValues[i] = Integer.MAX_VALUE; }//from w w w .ja va 2s. com for (int i = 0; i < functionsCount; i++) { HashFunction hf = functions[i]; for (Writable wr : values.get()) { IntWritable value = (IntWritable) wr; int hash = hf.hashInt(value.get()).asInt(); if (hash < hashValues[i]) { hashValues[i] = hash; } } } Text sketch = new Text(); Hasher hasher = lsh.newHasher(); int band = 0; for (int i = 0; i < functionsCount; i++) { hasher.putInt(hashValues[i]); if (i > 0 && (i % rows) == 0) { sketch.set(band + "-" + hasher.hash().toString()); context.write(new SecondarySortKey(sketch, id), id); hasher = lsh.newHasher(); band++; } } sketch.set(band + "-" + hasher.hash().toString()); context.write(new SecondarySortKey(sketch, id), id); }