Example usage for org.eclipse.jgit.lib Constants newMessageDigest

List of usage examples for org.eclipse.jgit.lib Constants newMessageDigest

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants newMessageDigest.

Prototype

public static MessageDigest newMessageDigest() 

Source Link

Document

Create a new digest function for objects.

Usage

From source file:com.google.gerrit.httpd.raw.CatServlet.java

License:Apache License

private String rand(final HttpServletRequest req, final String suffix) throws UnsupportedEncodingException {
    // Produce a random suffix that is difficult (or nearly impossible)
    // for an attacker to guess in advance. This reduces the risk that
    // an attacker could upload a *.class file and have us send a ZIP
    // that can be invoked through an applet tag in the victim's browser.
    ////from   w w  w.j  a  v a  2  s.co  m
    final MessageDigest md = Constants.newMessageDigest();
    final byte[] buf = new byte[8];

    NB.encodeInt32(buf, 0, req.getRemotePort());
    md.update(req.getRemoteAddr().getBytes("UTF-8"));
    md.update(buf, 0, 4);

    NB.encodeInt64(buf, 0, TimeUtil.nowMs());
    md.update(buf, 0, 8);

    rng.nextBytes(buf);
    md.update(buf, 0, 8);

    return suffix + "-" + ObjectId.fromRaw(md.digest()).name();
}

From source file:com.google.gerrit.server.account.GroupUUID.java

License:Apache License

public static AccountGroup.UUID make(String groupName, PersonIdent creator) {
    MessageDigest md = Constants.newMessageDigest();
    md.update(Constants.encode("group " + groupName + "\n"));
    md.update(Constants.encode("creator " + creator.toExternalString() + "\n"));
    return new AccountGroup.UUID(ObjectId.fromRaw(md.digest()).name());
}

From source file:org.ms123.common.git.FileHolder.java

License:Open Source License

private static ObjectId hash(final byte[] rawText) {
    return ObjectId.fromRaw(Constants.newMessageDigest().digest(rawText));
}

From source file:org.webcat.core.http.RequestUtils.java

License:Open Source License

/**
 * Computes the etag (SHA-1 hash) for the specified content.
 *
 * @param content the content/* w w w .  j av  a2  s .c  o  m*/
 * @return SHA-1 hash for the specified content
 */
private static String etag(byte[] content) {
    MessageDigest md = Constants.newMessageDigest();
    md.update(content);
    return ObjectId.fromRaw(md.digest()).getName();
}