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

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

Introduction

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

Prototype

public static String sha256Hex(String data) 

Source Link

Usage

From source file:spade.reporter.audit.artifact.ArtifactManager.java

public ArtifactManager(Audit reporter, Globals globals) throws Exception {
    if (reporter == null) {
        throw new IllegalArgumentException("NULL Audit reporter");
    }// w ww  . ja  v  a 2 s.com
    if (globals == null) {
        throw new IllegalArgumentException("NULL Globals object");
    }
    this.reporter = reporter;
    if (globals.keepingArtifactPropertiesMap) {
        String configFilePath = Settings.getDefaultConfigFilePath(this.getClass());
        Map<String, String> configMap = FileUtility.readConfigFileAsKeyValueMap(configFilePath, "=");
        artifactsMap = CommonFunctions.createExternalMemoryMapInstance(artifactsMapId,
                configMap.get("cacheSize"), configMap.get("bloomfilterFalsePositiveProbability"),
                configMap.get("bloomFilterExpectedNumberOfElements"), configMap.get("tempDir"),
                configMap.get("dbName"), configMap.get("reportingIntervalSeconds"),
                new Hasher<ArtifactIdentifier>() {
                    @Override
                    public String getHash(ArtifactIdentifier t) {
                        if (t != null) {
                            Map<String, String> annotations = t.getAnnotationsMap();
                            String subtype = t.getSubtype();
                            String stringToHash = String.valueOf(annotations) + "," + String.valueOf(subtype);
                            return DigestUtils.sha256Hex(stringToHash);
                        } else {
                            return DigestUtils.sha256Hex("(null)");
                        }
                    }
                });
    } else {
        artifactsMap = null;
    }
    artifactConfigs = getArtifactConfig(globals);
}

From source file:spade.storage.CompressedTextFile.java

@Override
public boolean putVertex(AbstractVertex incomingVertex) {
    try {/*  w w  w . j a va  2s .c o  m*/
        String vertexHash = DigestUtils.sha256Hex(incomingVertex.toString());
        Integer vertexId = nextVertexID;
        nextVertexID++;
        hashToID.put(vertexHash, vertexId);
        StringBuilder annotationString = new StringBuilder();
        //annotationString.append("VERTEX (" + vertexId + "): {");
        for (Map.Entry<String, String> currentEntry : incomingVertex.getAnnotations().entrySet()) {
            String key = currentEntry.getKey();
            String value = currentEntry.getValue();
            if (key == null || value == null) {
                continue;
            }
            annotationString.append(key);
            annotationString.append(":");
            annotationString.append(value);
            annotationString.append(",");
        }
        //annotationString.append("}\n");
        String vertexString = annotationString.toString();
        //outputFile.write(vertexString);
        byte[] input = vertexString.getBytes("UTF-8");
        byte[] output = new byte[input.length + 100];
        compresser.setInput(input);
        compresser.finish();
        int compressedDataLength = compresser.deflate(output);
        put(annotationsWriter, vertexId, output);
        compresser.reset();
        return true;
    } catch (Exception exception) {
        Logger.getLogger(TextFile.class.getName()).log(Level.SEVERE, null, exception);
        return false;
    }
}

From source file:spade.storage.CompressedTextFile.java

@Override
public boolean putEdge(AbstractEdge incomingEdge) {
    try {/*w  w  w.j  a va  2  s.  c  o m*/
        String srcHash = DigestUtils.sha256Hex(incomingEdge.getChildVertex().toString());
        String dstHash = DigestUtils.sha256Hex(incomingEdge.getParentVertex().toString());
        Integer srcID = hashToID.get(srcHash);
        Integer dstID = hashToID.get(dstHash);
        StringBuilder annotationString = new StringBuilder();
        //annotationString.append("EDGE (" + srcID + " -> " + dstID + "): {");
        for (Map.Entry<String, String> currentEntry : incomingEdge.getAnnotations().entrySet()) {
            String key = currentEntry.getKey();
            String value = currentEntry.getValue();
            if (key == null || value == null) {
                continue;
            }
            annotationString.append(key);
            annotationString.append(":");
            annotationString.append(value);
            annotationString.append(",");
        }
        //annotationString.append("}\n");
        //String edgeString = annotationString.toString();
        //annotationsWriter.write(edgeString);
        //annotationString.append("}\n");
        String edgeString = annotationString.toString();
        //outputFile.write(edgeString);
        byte[] input = edgeString.getBytes("UTF-8");
        byte[] output = new byte[input.length + 100];
        compresser.setInput(input);
        compresser.finish();
        int compressedDataLength = compresser.deflate(output);
        String key = srcID + "->" + dstID;
        put(annotationsWriter, key, output);
        compresser.reset();
        // scaffold storage
        //update scaffoldInMemory
        Pair<SortedSet<Integer>, SortedSet<Integer>> srcLists = scaffoldInMemory.get(srcID);
        if (srcLists == null) {
            srcLists = new Pair<SortedSet<Integer>, SortedSet<Integer>>(new TreeSet<Integer>(),
                    new TreeSet<Integer>());
        }
        srcLists.second().add(dstID);
        scaffoldInMemory.put(srcID, srcLists);
        Pair<SortedSet<Integer>, SortedSet<Integer>> dstLists = scaffoldInMemory.get(dstID);
        if (dstLists == null) {
            dstLists = new Pair<SortedSet<Integer>, SortedSet<Integer>>(new TreeSet<Integer>(),
                    new TreeSet<Integer>());
        }
        dstLists.first().add(dstID);
        scaffoldInMemory.put(dstID, dstLists);
        edgesInMemory++;
        if (edgesInMemory == maxEdgesInMemory) {
            updateAncestorsSuccessors(scaffoldInMemory);
            scaffoldInMemory.clear();
            edgesInMemory = 0;
            long aux = System.currentTimeMillis();
            benchmarks.println(aux - clock);
            clock = aux;
        }

        return true;
    } catch (Exception exception) {
        Logger.getLogger(TextFile.class.getName()).log(Level.SEVERE, null, exception);
        return false;
    }
}

From source file:spade.storage.Neo4j.java

public String getHashOfEdge(AbstractEdge edge) {
    String completeEdgeString = edge.getChildVertex().toString() + edge.toString()
            + edge.getParentVertex().toString();
    return DigestUtils.sha256Hex(completeEdgeString);
}

From source file:spade.storage.Neo4j.java

public String getHashOfVertex(AbstractVertex vertex) {
    return DigestUtils.sha256Hex(vertex.toString());
}

From source file:spade.storage.Prov.java

public String getSerializedVertex(AbstractVertex vertex) {
    String vertexString = null;//ww w. j a v  a  2 s. c o  m
    switch (provOutputFormat) {
    case PROVO:

        vertexString = String.format(provoStringFormatForVertex, defaultNamespacePrefix,
                DigestUtils.sha256Hex(vertex.toString()), provNamespacePrefix,
                vertex.getClass().getSimpleName(), getProvOFormattedKeyValPair(vertex.getAnnotations()));

        break;
    case PROVN:

        vertexString = String.format(provnStringFormatForVertex,
                vertex.getClass().getSimpleName().toLowerCase(), defaultNamespacePrefix,
                DigestUtils.sha256Hex(vertex.toString()), getProvNFormattedKeyValPair(vertex.getAnnotations()));

        break;
    default:
        break;
    }
    return vertexString;
}

From source file:spade.storage.Prov.java

public String getSerializedEdge(AbstractEdge edge) {
    String childVertexKey = DigestUtils.sha256Hex(edge.getChildVertex().toString());
    String destVertexKey = DigestUtils.sha256Hex(edge.getParentVertex().toString());
    String edgeString = null;//from w  w  w .  ja v a 2s .  c om
    switch (provOutputFormat) {
    case PROVO:
        edgeString = String.format(provoStringFormatsForEdgeTypes.get(edge.getClass().getName()),
                defaultNamespacePrefix, childVertexKey, provNamespacePrefix, provNamespacePrefix,
                provNamespacePrefix, defaultNamespacePrefix, destVertexKey,
                getProvOFormattedKeyValPair(edge.getAnnotations()));

        break;
    case PROVN:
        edgeString = String.format(provnStringFormatsForEdgeTypes.get(edge.getClass().getName()),
                defaultNamespacePrefix, childVertexKey, defaultNamespacePrefix, destVertexKey,
                getProvNFormattedKeyValPair(edge.getAnnotations()));
        break;
    default:
        break;
    }
    return edgeString;
}

From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java

@Test
public void testECSSLFingerprint() throws Exception {
    // setup/*from  w  w w . j ava  2  s  .  c  o m*/
    X509Certificate sslCert = TrustTestUtils.loadCertificateFromResource("eu/ec.europa.eu.der");

    // operate
    LOG.debug("EC SSL SHA-1 fingerprint: " + DigestUtils.shaHex(sslCert.getEncoded()));
    LOG.debug("EC SSL SHA-256 fingerprint: " + DigestUtils.sha256Hex(sslCert.getEncoded()));
}

From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java

@Test
public void testECFingerprint() throws Exception {
    // setup/*from   w  w w .  j a  va  2 s. c  o m*/
    Document euTSLDocument = TrustTestUtils.loadDocumentFromResource("eu/tl-mp-2.xml");
    TrustServiceList euTSL = TrustServiceListFactory.newInstance(euTSLDocument);
    X509Certificate euCertificate = euTSL.verifySignature();

    // operate
    LOG.debug("EC SHA-1 fingerprint: " + DigestUtils.shaHex(euCertificate.getEncoded()));
    LOG.debug("EC SHA-256 fingerprint: " + DigestUtils.sha256Hex(euCertificate.getEncoded()));
}

From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java

@Test
public void testNewECFingerprint() throws Exception {
    // setup/*from www  .j  av a  2 s  . c  o  m*/
    Document euTSLDocument = TrustTestUtils.loadDocumentFromResource("eu/tl-mp-33.xml");
    TrustServiceList euTSL = TrustServiceListFactory.newInstance(euTSLDocument);
    X509Certificate euCertificate = euTSL.verifySignature();

    // operate
    LOG.debug("EC SHA-1 fingerprint: " + DigestUtils.shaHex(euCertificate.getEncoded()));
    LOG.debug("EC SHA-256 fingerprint: " + DigestUtils.sha256Hex(euCertificate.getEncoded()));
}