Example usage for org.bouncycastle.cms CMSSignedGenerator DIGEST_MD5

List of usage examples for org.bouncycastle.cms CMSSignedGenerator DIGEST_MD5

Introduction

In this page you can find the example usage for org.bouncycastle.cms CMSSignedGenerator DIGEST_MD5.

Prototype

String DIGEST_MD5

To view the source code for org.bouncycastle.cms CMSSignedGenerator DIGEST_MD5.

Click Source Link

Usage

From source file:de.mendelson.util.security.BCCryptoHelper.java

/**
 * Converts the passed algorithm or OID/*from  ww w. ja va  2  s  . c o m*/
 */
public String convertAlgorithmNameToOID(String algorithm) throws NoSuchAlgorithmException {
    if (algorithm == null) {
        throw new NoSuchAlgorithmException(
                "convertAlgorithmNameToOID: Unable to proceed - Algorithm is absent");
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_MD5)) {
        return (CMSSignedGenerator.DIGEST_MD5);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_SHA1)) {
        return (CMSSignedGenerator.DIGEST_SHA1);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_SHA224) || algorithm.equalsIgnoreCase("sha224")) {
        return (CMSSignedGenerator.DIGEST_SHA224);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_SHA256) || algorithm.equalsIgnoreCase("sha256")) {
        return (CMSSignedGenerator.DIGEST_SHA256);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_SHA384) || algorithm.equalsIgnoreCase("sha384")) {
        return (CMSSignedGenerator.DIGEST_SHA384);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_SHA512) || algorithm.equalsIgnoreCase("sha512")) {
        return (CMSSignedGenerator.DIGEST_SHA512);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_3DES)) {
        return ("1.2.840.113549.3.7");
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_DES)) {
        return ("1.3.14.3.2.7");
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_CAST5)) {
        return (CMSEnvelopedDataGenerator.CAST5_CBC);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_IDEA)) {
        return (CMSEnvelopedDataGenerator.IDEA_CBC);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_RC2)) {
        return (CMSEnvelopedDataGenerator.RC2_CBC);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_RC4)) {
        return ("1.2.840.113549.3.4");
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_AES_128)) {
        return (CMSEnvelopedDataGenerator.AES128_CBC);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_AES_192)) {
        return (CMSEnvelopedDataGenerator.AES192_CBC);
    } else if (algorithm.equalsIgnoreCase(ALGORITHM_AES_256)) {
        return (CMSEnvelopedDataGenerator.AES256_CBC);
    } else {
        throw new NoSuchAlgorithmException("Unsupported algorithm: " + algorithm);
    }
}

From source file:de.mendelson.util.security.BCCryptoHelper.java

/**
 * Converts the passed algorithm or OID/*from ww  w  .j  ava  2  s .  c  o m*/
 */
public String convertOIDToAlgorithmName(String oid) throws NoSuchAlgorithmException {
    if (oid == null) {
        throw new NoSuchAlgorithmException("convertOIDToAlgorithmName: OID is absent");
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_MD5)) {
        return (ALGORITHM_MD5);
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_SHA1)) {
        return (ALGORITHM_SHA1);
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_SHA224)) {
        return (ALGORITHM_SHA224);
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_SHA256)) {
        return (ALGORITHM_SHA256);
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_SHA384)) {
        return (ALGORITHM_SHA384);
    } else if (oid.equalsIgnoreCase(CMSSignedGenerator.DIGEST_SHA512)) {
        return (ALGORITHM_SHA512);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.CAST5_CBC)) {
        return (ALGORITHM_CAST5);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.DES_EDE3_CBC)) {
        return (ALGORITHM_3DES);
    } else if (oid.equalsIgnoreCase("1.3.14.3.2.7")) {
        return (ALGORITHM_DES);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.IDEA_CBC)) {
        return (ALGORITHM_IDEA);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.RC2_CBC)) {
        return (ALGORITHM_RC2);
    } else if (oid.equalsIgnoreCase("1.2.840.113549.3.4")) {
        return (ALGORITHM_RC4);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.AES128_CBC)) {
        return (ALGORITHM_AES_128);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.AES192_CBC)) {
        return (ALGORITHM_AES_192);
    } else if (oid.equalsIgnoreCase(CMSEnvelopedDataGenerator.AES256_CBC)) {
        return (ALGORITHM_AES_256);
    } else {
        throw new NoSuchAlgorithmException("Unsupported algorithm: OID " + oid);
    }
}

From source file:org.cesecore.certificates.util.AlgorithmTools.java

License:Open Source License

/** 
 * Get the digest algorithm corresponding to the signature algorithm. This is used for the creation of
 * PKCS7 file. SHA1 shall always be used, but it is not working with GOST which needs GOST3411 digest.
 * //  w  w  w  .  j  a  v a2s .c  o m
 */
public static String getDigestFromSigAlg(String sigAlg) {
    if (sigAlg.toUpperCase().contains("GOST") || sigAlg.toUpperCase().contains("DSTU")) {
        return CMSSignedGenerator.DIGEST_GOST3411;
    } else {
        if (sigAlg.equals(X9ObjectIdentifiers.ecdsa_with_SHA1.getId())
                || sigAlg.equals(PKCSObjectIdentifiers.sha1WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_SHA1;
        } else if (sigAlg.equals(X9ObjectIdentifiers.ecdsa_with_SHA224.getId())
                || sigAlg.equals(PKCSObjectIdentifiers.sha224WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_SHA224;
        } else if (sigAlg.equals(X9ObjectIdentifiers.ecdsa_with_SHA256.getId())
                || sigAlg.equals(PKCSObjectIdentifiers.sha256WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_SHA256;
        } else if (sigAlg.equals(X9ObjectIdentifiers.ecdsa_with_SHA384.getId())
                || sigAlg.equals(PKCSObjectIdentifiers.sha384WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_SHA384;
        } else if (sigAlg.equals(X9ObjectIdentifiers.ecdsa_with_SHA512.getId())
                || sigAlg.equals(PKCSObjectIdentifiers.sha512WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_SHA512;
        } else if (sigAlg.equals(PKCSObjectIdentifiers.md5WithRSAEncryption.getId())) {
            return CMSSignedGenerator.DIGEST_MD5;
        } else if (sigAlg.equals(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001.getId())) {
            return CMSSignedGenerator.DIGEST_GOST3411;
        }
    }
    return CMSSignedGenerator.DIGEST_SHA1;

}

From source file:org.cesecore.certificates.util.AlgorithmTools.java

License:Open Source License

/** Calculates which signature algorithm to use given a key type and a digest algorithm
 * //from w  w w .j ava 2  s.  c om
 * @param digestAlg objectId of a digest algorithm, CMSSignedGenerator.DIGEST_SHA256 etc
 * @param keyAlg RSA, EC, DSA
 * @return ASN1ObjectIdentifier with the id of PKCSObjectIdentifiers.sha1WithRSAEncryption, X9ObjectIdentifiers.ecdsa_with_SHA1, X9ObjectIdentifiers.id_dsa_with_sha1, etc
 */
public static ASN1ObjectIdentifier getSignAlgOidFromDigestAndKey(final String digestAlg, final String keyAlg) {
    if (log.isTraceEnabled()) {
        log.trace(">getSignAlg(" + digestAlg + "," + keyAlg + ")");
    }
    // Default to SHA1WithRSA if everything else fails    
    ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.sha1WithRSAEncryption;
    if (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_EC)
            || keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECDSA)) {
        oid = X9ObjectIdentifiers.ecdsa_with_SHA1;
    } else if (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_DSA)) {
        oid = X9ObjectIdentifiers.id_dsa_with_sha1;
    } else if (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECGOST3410)) {
        oid = CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001;
    } else if (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_DSTU4145)) {
        oid = new ASN1ObjectIdentifier(CesecoreConfiguration.getOidDstu4145());
    }
    if (digestAlg != null) {
        if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA256)
                && keyAlg.equals(AlgorithmConstants.KEYALGORITHM_RSA)) {
            oid = PKCSObjectIdentifiers.sha256WithRSAEncryption;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA512)
                && keyAlg.equals(AlgorithmConstants.KEYALGORITHM_RSA)) {
            oid = PKCSObjectIdentifiers.sha512WithRSAEncryption;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_MD5)
                && keyAlg.equals(AlgorithmConstants.KEYALGORITHM_RSA)) {
            oid = PKCSObjectIdentifiers.md5WithRSAEncryption;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA256)
                && (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECDSA)
                        || keyAlg.equals(AlgorithmConstants.KEYALGORITHM_EC))) {
            oid = X9ObjectIdentifiers.ecdsa_with_SHA256;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA224)
                && (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECDSA)
                        || keyAlg.equals(AlgorithmConstants.KEYALGORITHM_EC))) {
            oid = X9ObjectIdentifiers.ecdsa_with_SHA224;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA384)
                && (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECDSA)
                        || keyAlg.equals(AlgorithmConstants.KEYALGORITHM_EC))) {
            oid = X9ObjectIdentifiers.ecdsa_with_SHA384;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA512)
                && (keyAlg.equals(AlgorithmConstants.KEYALGORITHM_ECDSA)
                        || keyAlg.equals(AlgorithmConstants.KEYALGORITHM_EC))) {
            oid = X9ObjectIdentifiers.ecdsa_with_SHA512;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA256)
                && keyAlg.equals(AlgorithmConstants.KEYALGORITHM_DSA)) {
            oid = NISTObjectIdentifiers.dsa_with_sha256;
        } else if (digestAlg.equals(CMSSignedGenerator.DIGEST_SHA512)
                && keyAlg.equals(AlgorithmConstants.KEYALGORITHM_DSA)) {
            oid = NISTObjectIdentifiers.dsa_with_sha512;
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("getSignAlgOidFromDigestAndKey: " + oid.getId());
    }
    return oid;
}

From source file:org.ejbca.core.protocol.scep.ProtocolScepHttpTest.java

License:Open Source License

@Test
public void test05ScepRequestOKMD5() throws Exception {
    // find a CA create a user and
    // send SCEP req to server and get good response with cert

    scepConfiguration.setIncludeCA(scepAlias, true);
    globalConfigSession.saveConfiguration(admin, scepConfiguration);

    // Make user that we know...
    createScepUser(userName1, userDN1);/*from  www. j  av  a 2  s  .c  o m*/

    byte[] msgBytes = genScepRequest(false, CMSSignedGenerator.DIGEST_MD5, userDN1);
    // Send message with GET
    byte[] retMsg = sendScep(false, msgBytes);
    assertNotNull(retMsg);
    checkScepResponse(retMsg, userDN1, senderNonce, transId, false, CMSSignedGenerator.DIGEST_MD5, false);

}