Example usage for org.eclipse.jgit.util NB encodeInt32

List of usage examples for org.eclipse.jgit.util NB encodeInt32

Introduction

In this page you can find the example usage for org.eclipse.jgit.util NB encodeInt32.

Prototype

public static void encodeInt32(final byte[] intbuf, final int offset, int v) 

Source Link

Document

Write a 32 bit integer as a sequence of 4 bytes (network byte order).

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.
    ///*w  w  w .j av a2s. c o 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();
}