List of usage examples for com.google.common.hash HashCode asBytes
@CheckReturnValue public abstract byte[] asBytes();
From source file:org.kmworks.util.crypto.Hashing.java
public static byte[] md5(String s) { HashFunction hf = com.google.common.hash.Hashing.md5(); HashCode hc = hf.newHasher().putString(s, Charsets.UTF_8).hash(); return hc.asBytes(); }
From source file:com.facebook.buck.rules.AbstractSha1HashCode.java
public static Sha1HashCode fromHashCode(HashCode hashCode) { return Sha1HashCode.of(Hashing.sha1().newHasher().putBytes(hashCode.asBytes()).hash().toString()); }
From source file:org.gradle.internal.hash.HashUtil.java
public static String compactStringFor(HashCode hashCode) { return compactStringFor(hashCode.asBytes()); }
From source file:org.gradle.internal.hash.HashUtil.java
public static int compareHashCodes(HashCode a, HashCode b) { return compareHashCodes(a.asBytes(), b.asBytes()); }
From source file:net.fabricmc.loom.util.Checksum.java
public static boolean equals(File file, String checksum) { if (file == null) { return false; }// www . j a va2 s .c o m try { HashCode hash = Files.hash(file, Hashing.sha1()); StringBuilder builder = new StringBuilder(); for (Byte hashBytes : hash.asBytes()) { builder.append(Integer.toString((hashBytes & 0xFF) + 0x100, 16).substring(1)); } return builder.toString().equals(checksum); } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:com.netflix.dynomitemanager.sidecore.utils.SystemUtils.java
/** * Get a Md5 string which is similar to OS Md5sum *///w w w. j a va 2 s. c o m public static String md5(File file) { if (file == null) throw new IllegalArgumentException("file cannot be null"); try { HashCode hc = Files.hash(file, Hashing.md5()); return toHex(hc.asBytes()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.netflix.priam.utils.SystemUtils.java
/** * Get a Md5 string which is similar to OS Md5sum *//*from w w w . ja va2 s .c om*/ 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.facebook.buck.rules.Sha1HashCode.java
public static Sha1HashCode fromHashCode(HashCode hashCode) { Preconditions.checkNotNull(hashCode); return new Sha1HashCode(Hashing.sha1().newHasher().putBytes(hashCode.asBytes()).hash().toString()); }
From source file:com.sonatype.nexus.repository.nuget.internal.odata.NugetPackageUtils.java
/** * Determine the metadata for a nuget package. * - nuspec data (comes from .nuspec)// www . j av a 2s. c o m * - size (package size) * - hash(es) (package hash sha-512) */ public static Map<String, String> packageMetadata(final InputStream inputStream) throws IOException, NugetPackageException { try (MultiHashingInputStream hashingStream = new MultiHashingInputStream( Arrays.asList(HashAlgorithm.SHA512), inputStream)) { final byte[] nuspec = extractNuspec(hashingStream); Map<String, String> metadata = NuspecSplicer.extractNuspecData(new ByteArrayInputStream(nuspec)); ByteStreams.copy(hashingStream, ByteStreams.nullOutputStream()); metadata.put(PACKAGE_SIZE, String.valueOf(hashingStream.count())); HashCode code = hashingStream.hashes().get(HashAlgorithm.SHA512); metadata.put(PACKAGE_HASH, new String(Base64.encodeBase64(code.asBytes()), Charsets.UTF_8)); metadata.put(PACKAGE_HASH_ALGORITHM, "SHA512"); return metadata; } catch (XmlPullParserException e) { throw new NugetPackageException("Unable to read .nuspec from package stream", e); } }
From source file:org.opendaylight.md.controller.topology.lldp.utils.LLDPDiscoveryUtils.java
/** * @param nodeConnectorId//from w w w . ja va 2 s .com * @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(); }