Example usage for com.google.common.hash Hashing sha1

List of usage examples for com.google.common.hash Hashing sha1

Introduction

In this page you can find the example usage for com.google.common.hash Hashing sha1.

Prototype

public static HashFunction sha1() 

Source Link

Document

Returns a hash function implementing the SHA-1 algorithm (160 hash bits) by delegating to the SHA-1 MessageDigest .

Usage

From source file:tech.beshu.ror.acl.blocks.rules.impl.SessionCookie.java

private String mkCookie(String userName, Date expiry) {
    return new StringBuilder().append(userName).append(COOKIE_STRING_SEPARATOR).append(expiry.toString())
            .append(COOKIE_STRING_SEPARATOR).append(Hashing.sha1()
                    .hashString(SERVER_SECRET + userName + expiry.getTime() / 1000, StandardCharsets.UTF_8))
            .toString();/*from w  w  w  .  j  av a 2 s .c o  m*/
}

From source file:com.facebook.buck.rules.keys.RuleKeyBuilder.java

public RuleKeyBuilder(SourcePathRuleFinder ruleFinder, SourcePathResolver resolver, FileHashLoader hashLoader) {
    this(ruleFinder, resolver, hashLoader,
            LoggingRuleKeyHasher.of(new GuavaRuleKeyHasher(Hashing.sha1().newHasher())));
}

From source file:org.fenixedu.academic.ui.struts.action.student.ICalStudentTimeTable.java

public static String calculatePayload(String to, Registration reg, User user) throws Exception {

    Cipher cipher = Cipher.getInstance("AES");

    SecretKeySpec skeySpec = new SecretKeySpec(user.getPrivateKey().getPrivateKey(), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

    byte[] encrypted = cipher.doFinal(("This is for " + to + " calendar ##" + "1.6180339##Sistema Fenix##"
            + user.getPrivateKey().getPrivateKeyCreation().toString() + "##" + reg.getExternalId() + "##"
            + user.getPrivateKey().getPrivateKeyValidity().toString() + "##" + "## This is for " + to
            + " calendar").getBytes(StandardCharsets.UTF_8));

    return Hashing.sha1().hashBytes(encrypted).toString();
}

From source file:org.apache.beam.sdk.testing.FileChecksumMatcher.java

private String computeHash(@Nonnull List<String> strs) {
    if (strs.isEmpty()) {
        return Hashing.sha1().hashString("", StandardCharsets.UTF_8).toString();
    }/* w  ww  .  j a  v a  2s  . co  m*/

    List<HashCode> hashCodes = new ArrayList<>();
    for (String str : strs) {
        hashCodes.add(Hashing.sha1().hashString(str, StandardCharsets.UTF_8));
    }
    return Hashing.combineUnordered(hashCodes).toString();
}

From source file:org.gsafeproject.storage.webresource.DocumentResource.java

private void checkFileIntegrity(InputStream fileStream, String fingerprint) throws IOException {
    File temp = File.createTempFile("temp", ".tmp");
    ByteStreams.copy(fileStream, new FileOutputStream(temp));
    if (!Files.hash(temp, Hashing.sha1()).toString().equalsIgnoreCase(fingerprint)) {
        throw new BadRequest("Supplied fingerprint is different from document hash");
    }//  ww w .j  a  v a2  s.c o m
    if (!temp.delete()) {
        LOGGER.warn("Temp file " + temp.getAbsolutePath() + " has not been deleted");
    }
}

From source file:com.google.gitiles.doc.DocServlet.java

private String etag(SourceFile srcmd, SourceFile navmd) {
    byte[] b = new byte[Constants.OBJECT_ID_LENGTH];
    Hasher h = Hashing.sha1().newHasher();
    h.putInt(ETAG_GEN);/*from w  w w.  j a va  2s. c om*/

    renderer.getTemplateHash(SOY_FILE).writeBytesTo(b, 0, b.length);
    h.putBytes(b);

    if (navmd != null) {
        navmd.id.copyRawTo(b, 0);
        h.putBytes(b);
    }

    srcmd.id.copyRawTo(b, 0);
    h.putBytes(b);
    return h.hash().toString();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.student.ICalStudentTimeTable.java

public static String calculatePayload(String to, Registration reg, User user) throws Exception {

    Cipher cipher = Cipher.getInstance("AES");

    SecretKeySpec skeySpec = new SecretKeySpec(user.getPrivateKey().getPrivateKey().getBytes(), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

    byte[] encrypted = cipher.doFinal(("This is for " + to + " calendar ##" + "1.6180339##Sistema Fenix##"
            + user.getPrivateKey().getPrivateKeyCreation().toString() + "##" + reg.getExternalId() + "##"
            + user.getPrivateKey().getPrivateKeyValidity().toString() + "##" + "## This is for " + to
            + " calendar").getBytes());

    return Hashing.sha1().hashBytes(encrypted).toString();
}

From source file:com.difference.historybook.index.lucene.IndexDocumentAdapter.java

/**
 * @param content The textual content of the page
 * @return this for method chaining/*ww  w  . j  a v  a2  s  .  c om*/
 */
public IndexDocumentAdapter setContent(String content) {
    doc.add(new TextField(FIELD_SEARCH, content, Field.Store.YES));

    String hash = Hashing.sha1().newHasher().putString(content, Charsets.UTF_8).hash().toString();
    doc.add(new StringField(FIELD_KEY, hash, Field.Store.YES));

    return this;
}

From source file:de.brendamour.jpasskit.signing.PKFileBasedSigningUtil.java

private File createManifestJSONFile(final File tempPassDir) throws PKSigningException {
    Map<String, String> fileWithHashMap = new HashMap<String, String>();

    HashFunction hashFunction = Hashing.sha1();
    File[] filesInTempDir = tempPassDir.listFiles();
    hashFilesInDirectory(filesInTempDir, fileWithHashMap, hashFunction, null);
    File manifestJSONFile = new File(tempPassDir.getAbsolutePath() + File.separator + MANIFEST_JSON_FILE_NAME);

    try {//from   w  ww  .ja v a 2 s  .  com
        objectWriter.writeValue(manifestJSONFile, fileWithHashMap);
    } catch (IOException e) {
        throw new PKSigningException("Error when writing manifest.json", e);
    }
    return manifestJSONFile;
}

From source file:com.facebook.buck.java.AccumulateClassNames.java

@VisibleForTesting
static Sha1HashCode computeAbiKey(Supplier<ImmutableSortedMap<String, HashCode>> classNames) {
    Hasher hasher = Hashing.sha1().newHasher();
    for (Map.Entry<String, HashCode> entry : classNames.get().entrySet()) {
        hasher.putUnencodedChars(entry.getKey());
        hasher.putByte((byte) 0);
        hasher.putUnencodedChars(entry.getValue().toString());
        hasher.putByte((byte) 0);
    }//from ww  w  . ja  v a 2  s.  co  m
    return new Sha1HashCode(hasher.hash().toString());
}