Example usage for org.apache.commons.codec.digest DigestUtils getSha256Digest

List of usage examples for org.apache.commons.codec.digest DigestUtils getSha256Digest

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils getSha256Digest.

Prototype

public static MessageDigest getSha256Digest() 

Source Link

Usage

From source file:com.dtolabs.rundeck.core.plugins.PluginUtils.java

public static String generateShaIdFromName(String pluginName) {
    MessageDigest digest = DigestUtils.getSha256Digest();
    digest.update(pluginName.getBytes());
    return bytesAsHex(digest.digest()).substring(0, 12);
}

From source file:com.continusec.client.Util.java

/**
 * Calculate the Merkle Tree Node Hash for an existing left and right hash (HASH(chr(1) || l || r)).
 * @param l the left node hash.//from w  ww  .  j  a  va 2  s  . c o  m
 * @param r the right node hash.
 * @return the node hash for the combination.
 */
public static final byte[] nodeMerkleTreeHash(byte[] l, byte[] r) {
    MessageDigest d = DigestUtils.getSha256Digest();
    d.update((byte) 1);
    d.update(l);
    d.update(r);
    return d.digest();
}

From source file:com.continusec.client.Util.java

/**
 * Calculate the Merkle Tree Leaf Hash for an object (HASH(chr(0) || b)).
 * @param b the input to the leaf hash//  ww w.ja va 2s  . co  m
 * @return the leaf hash.
 */
public static final byte[] leafMerkleTreeHash(byte[] b) {
    MessageDigest d = DigestUtils.getSha256Digest();
    d.update((byte) 0);
    d.update(b);
    return d.digest();
}

From source file:customerproject.customerutilities.Utilities.java

public static String SHA256(String email, String password)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {

    String text = email + "." + password;
    MessageDigest md = DigestUtils.getSha256Digest();

    byte[] sha256hash = new byte[32];
    md.update(text.getBytes("iso-8859-1"), 0, text.length());
    sha256hash = md.digest();//from ww  w .jav a  2s.c om

    //return Base64.encodeBase64String(sha256hash);
    return Base64.encodeBase64URLSafeString(sha256hash);
    //String hex = convertToHex(sha256hash);

}

From source file:com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup.java

public String etag() {
    try {/*from  w  w w.j  av a2  s . c om*/
        MessageDigest digest = DigestUtils.getSha256Digest();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
                new DigestOutputStream(new NullOutputStream(), digest));
        outputStreamWriter.write(name);
        outputStreamWriter.write("/");
        outputStreamWriter.write(Integer.toString(permissions.hashCode()));
        outputStreamWriter.write("[");

        for (Map.Entry<String, GoDashboardPipeline> entry : pipelines.entrySet()) {
            long lastUpdatedTimeStamp = entry.getValue().getLastUpdatedTimeStamp();
            outputStreamWriter.write(entry.getKey());
            outputStreamWriter.write(":");
            outputStreamWriter.write(Long.toString(lastUpdatedTimeStamp));
        }

        outputStreamWriter.write("]");
        outputStreamWriter.flush();

        return Hex.encodeHexString(digest.digest());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.continusec.client.Util.java

/**
 * Create the path in a sparse merkle tree for a given key. ie a boolean array representing
 * the big-endian index of the the hash of the key.
 * @param key the key/*w w w.ja v  a  2 s.  c  om*/
 * @return a length 256 array of booleans representing left (false) and right (true) path in the Sparse Merkle Tree.
 */
public static final boolean[] constructMapKeyPath(byte[] key) {
    byte[] h = DigestUtils.getSha256Digest().digest(key);
    boolean[] rv = new boolean[h.length * 8];
    for (int i = 0; i < h.length; i++) {
        for (int j = 0; j < 8; j++) {
            if (((h[i] >> j) & 1) == 1) {
                rv[(i << 3) + 7 - j] = true;
            }
        }
    }
    return rv;
}

From source file:com.thoughtworks.go.server.dashboard.AbstractDashboardGroup.java

protected String digest(String permissionsSegment) {
    try {//from   w ww.jav  a  2s  .  c  om
        MessageDigest digest = DigestUtils.getSha256Digest();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
                new DigestOutputStream(new NullOutputStream(), digest));
        outputStreamWriter.write(getClass().getSimpleName());
        outputStreamWriter.write("$");
        outputStreamWriter.write(name());
        outputStreamWriter.write("/");
        outputStreamWriter.write(permissionsSegment);
        outputStreamWriter.write("[");

        for (GoDashboardPipeline pipeline : allPipelines()) {
            outputStreamWriter.write(pipeline.cacheSegment());
            outputStreamWriter.write(",");
        }

        outputStreamWriter.write("]");
        outputStreamWriter.flush();

        return Hex.encodeHexString(digest.digest());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.continusec.client.ObjectHash.java

private static final byte[] hashNull() throws ContinusecException {
    MessageDigest d = DigestUtils.getSha256Digest();
    d.update((byte) 'n');
    return d.digest();
}

From source file:com.continusec.client.ObjectHash.java

private static final byte[] hashArray(JsonArray a, String r) throws ContinusecException {
    MessageDigest d = DigestUtils.getSha256Digest();
    d.update((byte) 'l');
    for (JsonElement e : a) {
        d.update(objectHashWithRedaction(e, r));
    }//from   www  .j a v a2 s . c  o m
    return d.digest();
}

From source file:com.continusec.client.ObjectHash.java

private static final byte[] hashObject(JsonObject o, String r) throws ContinusecException {
    ArrayList<byte[]> entries = new ArrayList<byte[]>();
    for (Map.Entry<String, JsonElement> e : o.entrySet()) {
        entries.add(ArrayUtils.addAll(hashString(e.getKey(), r), objectHashWithRedaction(e.getValue(), r)));
    }/*w  w  w.j  a  v  a  2 s . c o  m*/
    Collections.sort(entries, ByteArrayComparator.getInstance());

    MessageDigest d = DigestUtils.getSha256Digest();
    d.update((byte) 'd');
    for (byte[] b : entries) {
        d.update(b);
    }
    return d.digest();
}