List of usage examples for com.google.common.hash Hashing sha1
public static HashFunction sha1()
From source file:com.zxy.commons.codec.utils.SHAUtils.java
/** * sha1 encode/*from www .java 2s . c om*/ * * @param source * @return sha1 encode string */ public static String encodeSHA1(String source) { return Hashing.sha1().hashBytes(source.getBytes()).toString(); }
From source file:org.glowroot.common.util.Versions.java
public static String getVersion(AbstractMessage obj) { return Hashing.sha1().hashBytes(obj.toByteArray()).toString(); }
From source file:net.fabricmc.loom.util.Checksum.java
public static boolean equals(File file, String checksum) { if (file == null) { return false; }//from w w w. j ava 2 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:org.sonatype.nexus.internal.node.NodeIdEncoding.java
/** * Return node-id for certificate.//from w ww . j av a 2s . c om */ public static String nodeIdForCertificate(final Certificate cert) throws CertificateEncodingException { checkNotNull(cert); String sha1 = Hashing.sha1().hashBytes(cert.getEncoded()).toString().toUpperCase(Locale.US); return nodeIdForSha1(sha1); }
From source file:com.hemouna.servico.RestLogin.java
@GET @Produces(MediaType.APPLICATION_JSON)//from ww w .ja v a2 s . c om public Response listarHospitais(@QueryParam("login") String login, @QueryParam("senha") String pass) { try { Hospital h = new HospitalDao().buscaLogin(login); pass = Hashing.sha1().hashString(pass, Charsets.UTF_8).toString(); if (!pass.equals(h.getSenha())) { return Response.status(Response.Status.UNAUTHORIZED).build(); } h.setSenha(""); String json = new Gson().toJson(h); return Response.status(Response.Status.OK).entity(json).build(); } catch (Exception e) { return Response.status(Response.Status.UNAUTHORIZED).build(); } }
From source file:ro.cosu.vampires.server.values.FileInfo.java
public static Optional<FileInfo> fromFile(File file) { String hash = null;/*from w w w .jav a 2 s.c o m*/ FileInfo result = null; try { hash = Files.asByteSource(file).hash(Hashing.sha1()).toString(); String name = file.getName(); long size = file.length(); result = new AutoValue_FileInfo(size, hash, name); } catch (IOException e) { LOG.error("can not create info for " + file.getName(), e); } return Optional.ofNullable(result); }
From source file:com.streamsets.pipeline.lib.hashing.HashingUtil.java
public static HashFunction getHasher(String hashAlgorithm) { switch (hashAlgorithm) { case "murmur3_128": return Hashing.murmur3_128(); case "MD5": return Hashing.md5(); case "SHA-1": return Hashing.sha1(); case "SHA-256": return Hashing.sha256(); default:/* w w w. j ava2 s .com*/ throw new IllegalArgumentException(Utils.format("Unsupported Hashing Algorithm: {}", hashAlgorithm)); } }
From source file:com.facebook.buck.java.classes.AbstractFileLike.java
@Override public HashCode fastHash() throws IOException { // Default non-fast implementation. return ByteStreams.hash(new FileLikeInputSupplier(this), Hashing.sha1()); }
From source file:io.soabase.core.features.logging.LoggingFile.java
public LoggingFile(File file) { this.file = Preconditions.checkNotNull(file, "file cannot be null"); this.key = Hashing.sha1().hashString(file.getPath(), Charsets.UTF_8).toString(); this.name = file.getName(); }
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()); }