Example usage for javax.xml.crypto.dsig DigestMethod SHA512

List of usage examples for javax.xml.crypto.dsig DigestMethod SHA512

Introduction

In this page you can find the example usage for javax.xml.crypto.dsig DigestMethod SHA512.

Prototype

String SHA512

To view the source code for javax.xml.crypto.dsig DigestMethod SHA512.

Click Source Link

Document

The <a href="http://www.w3.org/2001/04/xmlenc#sha512"> SHA512</a> digest method algorithm URI.

Usage

From source file:edu.isi.misd.tagfiler.util.LocalFileChecksum.java

/**
 * Computes a checksum on a file, given the proper message digest
 * implementation// w w  w .  j  av  a 2 s. com
 * 
 * @param file
 *            file to read
 * @param messageDigest
 *            MessageDigest to use
 * @return the checksum bytes of the file
 * @thows FatalException if the checksum cannot be constructed.
 */
public static String computeFileChecksum(File file) throws FatalException {
    if (file == null)
        throw new IllegalArgumentException("file");

    String checksum = null;

    FileInputStream stream = null;
    try {
        stream = new FileInputStream(file);
        if (DigestMethod.SHA512.equals(digestType)) {
            checksum = DigestUtils.sha512Hex(stream);
        } else if (DigestMethod.SHA256.equals(digestType)) {
            checksum = DigestUtils.sha256Hex(stream);
        } else if (DigestMethod.SHA1.equals(digestType)) {
            checksum = DigestUtils.shaHex(stream);
        } else {
            checksum = DigestUtils.md5Hex(stream);
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new FatalException(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }
    return checksum;
}

From source file:gov.nih.nci.cacis.nav.DefaultDocumentReferenceValidator.java

/**
 * Default Constructor//  w w  w  .ja v a2  s  .c  om
 */
public DefaultDocumentReferenceValidator() {
    supportedAlgorithms.put(DigestMethod.SHA1, "SHA-1");
    supportedAlgorithms.put(DigestMethod.SHA256, "SHA-256");
    supportedAlgorithms.put(DigestMethod.SHA512, "SHA-512");
}

From source file:ee.ria.xroad.common.util.CryptoUtils.java

/**
 * Returns the digest/signature algorithm URI for the given digest/signature algorithm identifier.
 * @param algoId the id of the algorithm
 * @return the URI of the algorithm//from w ww.  j  a v  a2  s .  c  om
 * @throws NoSuchAlgorithmException if the algorithm id is unknown
 */
public static String getDigestAlgorithmURI(String algoId) throws NoSuchAlgorithmException {
    switch (algoId) {
    case SHA1_ID:
        return DigestMethod.SHA1;
    case SHA224_ID:
        return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224;
    case SHA256_ID:
        return DigestMethod.SHA256;
    case SHA384_ID:
        return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384;
    case SHA512_ID:
        return DigestMethod.SHA512;
    default:
        throw new NoSuchAlgorithmException("Unknown algorithm id: " + algoId);
    }
}

From source file:ee.ria.xroad.common.util.CryptoUtils.java

/**
 * Returns the digest/signature algorithm identifier for the given digest/signature algorithm URI.
 * @param algoURI the URI of the algorithm
 * @return the identifier of the algorithm
 * @throws NoSuchAlgorithmException if the algorithm URI is unknown
 *//*  ww w .ja v a  2s  . c  om*/
public static String getAlgorithmId(String algoURI) throws NoSuchAlgorithmException {
    switch (algoURI) {
    case DigestMethod.SHA1:
        return SHA1_ID;
    case MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224:
        return SHA224_ID;
    case DigestMethod.SHA256:
        return SHA256_ID;
    case MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384:
        return SHA384_ID;
    case DigestMethod.SHA512:
        return SHA512_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA1:
        return SHA1WITHRSA_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA256:
        return SHA256WITHRSA_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA384:
        return SHA384WITHRSA_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA512:
        return SHA512WITHRSA_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA256_MGF1:
        return SHA256WITHRSAANDMGF1_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA384_MGF1:
        return SHA384WITHRSAANDMGF1_ID;
    case ALGO_ID_SIGNATURE_RSA_SHA512_MGF1:
        return SHA512WITHRSAANDMGF1_ID;
    default:
        throw new NoSuchAlgorithmException("Unknown algorithm URI: " + algoURI);
    }
}

From source file:at.gv.egiz.bku.slcommands.impl.cms.Signature.java

private void setAlgorithmIDs(X509Certificate signingCertificate, boolean useStrongHash)
        throws NoSuchAlgorithmException {
    AlgorithmMethodFactory amf = new AlgorithmMethodFactoryImpl(signingCertificate, useStrongHash);
    signatureAlgorithmURI = amf.getSignatureAlgorithmURI();
    signatureAlgorithm = amf.getSignatureAlgorithmID();
    if (digestAlgorithm != null) {
        if (AlgorithmID.sha1.equals(digestAlgorithm)) {
            digestAlgorithmURI = DigestMethod.SHA1;
        } else if (AlgorithmID.sha256.equals(digestAlgorithm)) {
            digestAlgorithmURI = DigestMethod.SHA256;
        } else if (AlgorithmID.sha512.equals(digestAlgorithm)) {
            digestAlgorithmURI = DigestMethod.SHA512;
        } else if (AlgorithmID.ripeMd160.equals(digestAlgorithm)) {
            digestAlgorithmURI = DigestMethod.RIPEMD160;
        } else {/*from w  w  w  .  ja  va  2  s .  c  o  m*/
            throw new NoSuchAlgorithmException("Algorithm '" + digestAlgorithm + "' not supported.");
        }
    } else {
        digestAlgorithmURI = amf.getDigestAlgorithmURI();
        digestAlgorithm = amf.getDigestAlgorithmID();
    }
}

From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.AbstractXmlSignatureService.java

private static String getXmlDigestAlgo(final String digestAlgo) {
    if ("SHA1".equals(digestAlgo) || "SHA-1".equals(digestAlgo) || "SHA".equals(digestAlgo)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        return DigestMethod.SHA1;
    }/*ww w.  j a v  a 2 s  .co m*/
    if ("SHA-256".equals(digestAlgo) || "SHA256".equals(digestAlgo)) { //$NON-NLS-1$ //$NON-NLS-2$
        return DigestMethod.SHA256;
    }
    if ("SHA-512".equals(digestAlgo) || "SHA512".equals(digestAlgo)) { //$NON-NLS-1$ //$NON-NLS-2$
        return DigestMethod.SHA512;
    }
    throw new IllegalArgumentException("unsupported digest algo: " + digestAlgo); //$NON-NLS-1$
}

From source file:be.fedict.eid.applet.service.signer.AbstractXmlSignatureService.java

private String getXmlDigestAlgo(String digestAlgo) {
    if ("SHA-1".equals(digestAlgo)) {
        return DigestMethod.SHA1;
    }// w w w. j  ava2s  .  com
    if ("SHA-256".equals(digestAlgo)) {
        return DigestMethod.SHA256;
    }
    if ("SHA-512".equals(digestAlgo)) {
        return DigestMethod.SHA512;
    }
    throw new RuntimeException("unsupported digest algo: " + digestAlgo);
}

From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java

private String getShortAlgoName(String longAlgoName) {
    if (DigestMethod.SHA1.equals(longAlgoName)) {
        return "SHA1";
    } else if (DigestMethod.SHA256.equals(longAlgoName)) {
        return "SHA256";
    } else if (DigestMethod.SHA512.equals(longAlgoName)) {
        return "SHA512";
    } else {//from   ww  w  . ja va2s  . c om
        throw new RuntimeException("Algorithm " + longAlgoName + " not supported");
    }
}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

public static String getDigestAlgo(String xmlDigestAlgo) {
    if (DigestMethod.SHA1.equals(xmlDigestAlgo)) {
        return "SHA-1";
    }// w  w  w  .ja va2  s .  co  m
    if (DigestMethod.SHA256.equals(xmlDigestAlgo)) {
        return "SHA-256";
    }
    if (DigestMethod.SHA512.equals(xmlDigestAlgo)) {
        return "SHA-512";
    }
    throw new RuntimeException("unsupported XML digest algo: " + xmlDigestAlgo);
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected String getMessageDigestAlgorithm(String xmlSigDigestMethod, String errorMessage)
        throws XmlSignatureException {
    String algorithm;/*from   w  w w . jav  a  2s.com*/
    if (DigestMethod.SHA1.equals(xmlSigDigestMethod)) {
        algorithm = "SHA-1";
    } else if (DigestMethod.SHA256.equals(xmlSigDigestMethod)) {
        algorithm = "SHA-256";
    } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(xmlSigDigestMethod)) {
        algorithm = "SHA-384";
    } else if (DigestMethod.SHA512.equals(getDigestAlgorithmForSigningCertificate())) {
        algorithm = "SHA-512";
    } else {
        throw new XmlSignatureException(String.format(errorMessage, xmlSigDigestMethod));
    }
    return algorithm;
}