List of usage examples for com.google.common.hash HashFunction newHasher
Hasher newHasher();
From source file:com.taobao.tanggong.HashUtil.java
public static String md5Hash(String src) { HashFunction hf = Hashing.md5(); HashCode hc = hf.newHasher().putString(src).hash(); return hc.toString(); }
From source file:epoxide.lpa.impl.StringUtil.java
public static String hash(HashFunction hf, Kryo kryo, Object obj) { Hasher ho = hf.newHasher(); Output out = new Output(Funnels.asOutputStream(ho)); kryo.writeClassAndObject(out, obj);// ww w . ja v a 2s . c om out.close(); return hex(ho.hash().asBytes()); }
From source file:io.github.maxymania.powercache.hash.Util.java
public static byte[] hash(HashFunction hf, Object obj) { Hasher digest = hf.newHasher(); digest.putObject(obj, funnel);/*www. ja v a2s . c om*/ return digest.hash().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:norbert.mynemo.dataimport.StringUserDataModel.java
/** * Returns the hash of the given user name. * * @param name a user name/*from www . ja v a 2s . c o m*/ * @return the hash of the user name */ public static long convertUsername(String name) { HashFunction hashFonction = Hashing.murmur3_128(); return hashFonction.newHasher().putString(name, Charsets.UTF_8).hash().asLong(); }
From source file:io.github.maxymania.powercache.hash.Util.java
public static byte[] hash(HashFunction hf, String catname, Object[] obj) { Hasher digest = hf.newHasher(); digest.putString(catname, UTF);/*from w w w.j av a2s. c o m*/ digest.putObject(obj, funnel); return digest.hash().asBytes(); }
From source file:org.onosproject.net.link.ProbedLinkProvider.java
/** * Build a stringified MAC address using the ClusterMetadata hash for uniqueness. * Form of MAC is "02:eb" followed by four bytes of clusterMetadata hash. * * @param cm cluster metadata/*from w ww .j a v a 2 s.co m*/ * @return stringified mac address */ static String fingerprintMac(ClusterMetadata cm) { if (cm == null) { return DEFAULT_MAC; } HashFunction hf = Hashing.murmur3_32(); HashCode hc = hf.newHasher().putObject(cm, ClusterMetadata.HASH_FUNNEL).hash(); int unqf = hc.asInt(); StringBuilder sb = new StringBuilder(); sb.append("02:eb"); for (int i = 0; i < 4; i++) { byte b = (byte) (unqf >> i * 8); sb.append(String.format(":%02X", b)); } return sb.toString(); }
From source file:com.github.luluvise.droid_utils.lib.HashUtils.java
/** * Gets a String hash generated using the passed hashing algorithm. *//* w ww.ja va 2s .co m*/ @Nonnull public static String getHash(@Nonnull HashFunction hash, @Nonnull String... strings) { Hasher hasher = hash.newHasher(); for (String input : strings) { hasher.putString(input); } return hasher.hash().toString(); }
From source file:com.github.marcosalis.kraken.utils.HashUtils.java
/** * Gets a String hash generated using the passed hashing algorithm. *///w w w . ja v a2 s . c om @Nonnull public static String getHash(@Nonnull HashFunction hash, @Nonnull String... strings) { final Hasher hasher = hash.newHasher(); for (String input : strings) { hasher.putString(input); } return hasher.hash().toString(); }
From source file:com.vertixtech.antiquity.graph.ElementUtils.java
/** * <p>/*from w w w . j ava 2 s .c o m*/ * Calculate the private hash of an {@link Element}. * </p> * * <p> * The private hash contains only the properties of the {@link Element}, without its associated elements. * </p> * * <p> * The hash is calculated based on SHA1 algorithm * </p> * * TODO Handle arrays values properly. * * @param element * The element to calculate the private hash for. * @param excludedKeys * the keys to exclude when hash is calculated. * @return A string representation of the hash * @see HashCode#toString() */ public static String calculateElementPrivateHash(Element element, Set<String> excludedKeys) { Map<String, Object> props = ElementUtils.getPropertiesAsMap(element, excludedKeys); Joiner.MapJoiner propsJoiner = Joiner.on('&').withKeyValueSeparator("="); HashFunction hf = Hashing.sha1(); Hasher h = hf.newHasher(); h.putString("[" + element.getId().toString() + "]"); h.putString(propsJoiner.join(props)); return h.hash().toString(); }