Example usage for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha224

List of usage examples for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha224

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha224.

Prototype

ASN1ObjectIdentifier id_sha224

To view the source code for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha224.

Click Source Link

Document

2.16.840.1.101.3.4.2.4

Usage

From source file:TSAClient.java

License:Apache License

private ASN1ObjectIdentifier getHashObjectIdentifier(String algorithm) {
    if (algorithm.equals("MD2")) {
        return new ASN1ObjectIdentifier(PKCSObjectIdentifiers.md2.getId());
    } else if (algorithm.equals("MD5")) {
        return new ASN1ObjectIdentifier(PKCSObjectIdentifiers.md5.getId());
    } else if (algorithm.equals("SHA-1")) {
        return new ASN1ObjectIdentifier(OIWObjectIdentifiers.idSHA1.getId());
    } else if (algorithm.equals("SHA-224")) {
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha224.getId());
    } else if (algorithm.equals("SHA-256")) {
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha256.getId());
    } else if (algorithm.equals("SHA-384")) {
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha384.getId());
    } else if (algorithm.equals("SHA-512")) {
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha512.getId());
    } else {// ww w . j  a  v a2s.  c  o m
        return new ASN1ObjectIdentifier(algorithm);
    }
}

From source file:com.modemo.javase.signature.TSAClient.java

License:Apache License

private ASN1ObjectIdentifier getHashObjectIdentifier(String algorithm) {
    switch (algorithm) {
    case "MD2":
        return new ASN1ObjectIdentifier(PKCSObjectIdentifiers.md2.getId());
    case "MD5":
        return new ASN1ObjectIdentifier(PKCSObjectIdentifiers.md5.getId());
    case "SHA-1":
        return new ASN1ObjectIdentifier(OIWObjectIdentifiers.idSHA1.getId());
    case "SHA-224":
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha224.getId());
    case "SHA-256":
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha256.getId());
    case "SHA-384":
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha384.getId());
    case "SHA-512":
        return new ASN1ObjectIdentifier(NISTObjectIdentifiers.id_sha512.getId());
    default://from  w  w  w  .  java  2s  . c o  m
        return new ASN1ObjectIdentifier(algorithm);
    }
}

From source file:org.candlepin.util.X509CRLStreamWriter.java

License:Open Source License

protected static Digest createDigest(AlgorithmIdentifier digAlg) throws CryptoException {
    Digest dig;/*from ww w  .  j  a  va2 s  . c o m*/

    if (digAlg.getAlgorithm().equals(OIWObjectIdentifiers.idSHA1)) {
        dig = new SHA1Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha224)) {
        dig = new SHA224Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha256)) {
        dig = new SHA256Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha384)) {
        dig = new SHA384Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha512)) {
        dig = new SHA384Digest();
    } else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md5)) {
        dig = new MD5Digest();
    } else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md4)) {
        dig = new MD4Digest();
    } else {
        throw new CryptoException("Cannot recognize digest.");
    }

    return dig;
}

From source file:org.cesecore.certificates.ocsp.integrated.IntegratedOcspResponseTest.java

License:Open Source License

/**
 * Tests creating an OCSP response using the root CA cert.
 * Tests using both SHA1, SHA256 and SHA224 CertID. SHA1 and SHA256 should work, while SHA224 should give an error.
 *//*from   w w  w. java 2 s  .  c  om*/
@Test
public void testGetOcspResponseSanity() throws Exception {
    ocspResponseGeneratorTestSession.reloadOcspSigningCache();
    // An OCSP request
    OCSPReqBuilder gen = new OCSPReqBuilder();
    gen.addRequest(new JcaCertificateID(SHA1DigestCalculator.buildSha1Instance(), caCertificate,
            caCertificate.getSerialNumber()));
    Extension[] extensions = new Extension[1];
    extensions[0] = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false,
            new DEROctetString("123456789".getBytes()));
    gen.setRequestExtensions(new Extensions(extensions));
    OCSPReq req = gen.build();

    final int localTransactionId = TransactionCounter.INSTANCE.getTransactionNumber();
    // Create the transaction logger for this transaction.
    TransactionLogger transactionLogger = new TransactionLogger(localTransactionId,
            GuidHolder.INSTANCE.getGlobalUid(), "");
    // Create the audit logger for this transaction.
    AuditLogger auditLogger = new AuditLogger("", localTransactionId, GuidHolder.INSTANCE.getGlobalUid(), "");
    byte[] responseBytes = ocspResponseGeneratorSession
            .getOcspResponse(req.getEncoded(), null, "", "", null, auditLogger, transactionLogger)
            .getOcspResponse();
    assertNotNull("OCSP responder replied null", responseBytes);

    OCSPResp response = new OCSPResp(responseBytes);
    assertEquals("Response status not zero.", 0, response.getStatus());
    BasicOCSPResp basicOcspResponse = (BasicOCSPResp) response.getResponseObject();
    assertTrue("OCSP response was not signed correctly.", basicOcspResponse
            .isSignatureValid(new JcaContentVerifierProviderBuilder().build(caCertificate.getPublicKey())));
    SingleResp[] singleResponses = basicOcspResponse.getResponses();
    assertEquals("Delivered some thing else than one and exactly one response.", 1, singleResponses.length);
    assertEquals("Response cert did not match up with request cert", caCertificate.getSerialNumber(),
            singleResponses[0].getCertID().getSerialNumber());
    assertEquals("Status is not null (good)", null, singleResponses[0].getCertStatus());

    // Do the same test but using SHA256 as hash algorithm for CertID
    gen = new OCSPReqBuilder();
    gen.addRequest(new JcaCertificateID(
            new BcDigestCalculatorProvider().get(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256)),
            caCertificate, caCertificate.getSerialNumber()));
    extensions = new Extension[1];
    extensions[0] = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false,
            new DEROctetString("123456789".getBytes()));
    gen.setRequestExtensions(new Extensions(extensions));
    req = gen.build();
    responseBytes = ocspResponseGeneratorSession
            .getOcspResponse(req.getEncoded(), null, "", "", null, auditLogger, transactionLogger)
            .getOcspResponse();
    assertNotNull("OCSP responder replied null", responseBytes);
    response = new OCSPResp(responseBytes);
    assertEquals("Response status not zero.", 0, response.getStatus());
    basicOcspResponse = (BasicOCSPResp) response.getResponseObject();
    assertTrue("OCSP response was not signed correctly.", basicOcspResponse
            .isSignatureValid(new JcaContentVerifierProviderBuilder().build(caCertificate.getPublicKey())));
    singleResponses = basicOcspResponse.getResponses();
    assertEquals("Delivered some thing else than one and exactly one response.", 1, singleResponses.length);
    assertEquals("Response cert did not match up with request cert", caCertificate.getSerialNumber(),
            singleResponses[0].getCertID().getSerialNumber());
    assertEquals("Status is not null (good)", null, singleResponses[0].getCertStatus());

    // Do the same test but using SHA224 as hash algorithm for CertID to see that we get an error back
    gen = new OCSPReqBuilder();
    gen.addRequest(new JcaCertificateID(
            new BcDigestCalculatorProvider().get(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha224)),
            caCertificate, caCertificate.getSerialNumber()));
    extensions = new Extension[1];
    extensions[0] = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false,
            new DEROctetString("123456789".getBytes()));
    gen.setRequestExtensions(new Extensions(extensions));
    req = gen.build();
    responseBytes = ocspResponseGeneratorSession
            .getOcspResponse(req.getEncoded(), null, "", "", null, auditLogger, transactionLogger)
            .getOcspResponse();
    assertNotNull("OCSP responder replied null", responseBytes);
    response = new OCSPResp(responseBytes);
    // Response status 1 means malformed request
    assertEquals("Response status not zero.", 1, response.getStatus());
    basicOcspResponse = (BasicOCSPResp) response.getResponseObject();
    assertNull("No response object for this unsigned error response.", basicOcspResponse);

}

From source file:org.jmrtd.lds.SignedDataUtil.java

License:Open Source License

/**
 * Gets the common mnemonic string (such as "SHA1", "SHA256withRSA") given an OID.
 *
 * @param oid an OID/* w w  w . j  a v a  2 s  .  c o  m*/
 *
 * @throws NoSuchAlgorithmException if the provided OID is not yet supported
 */
public static String lookupMnemonicByOID(String oid) throws NoSuchAlgorithmException {
    if (oid == null) {
        return null;
    }
    if (oid.equals(X509ObjectIdentifiers.organization.getId())) {
        return "O";
    }
    if (oid.equals(X509ObjectIdentifiers.organizationalUnitName.getId())) {
        return "OU";
    }
    if (oid.equals(X509ObjectIdentifiers.commonName.getId())) {
        return "CN";
    }
    if (oid.equals(X509ObjectIdentifiers.countryName.getId())) {
        return "C";
    }
    if (oid.equals(X509ObjectIdentifiers.stateOrProvinceName.getId())) {
        return "ST";
    }
    if (oid.equals(X509ObjectIdentifiers.localityName.getId())) {
        return "L";
    }
    if (oid.equals(X509ObjectIdentifiers.id_SHA1.getId())) {
        return "SHA-1";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha224.getId())) {
        return "SHA-224";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha256.getId())) {
        return "SHA-256";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha384.getId())) {
        return "SHA-384";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha512.getId())) {
        return "SHA-512";
    }
    if (oid.equals(X9_SHA1_WITH_ECDSA_OID)) {
        return "SHA1withECDSA";
    }
    if (oid.equals(X9_SHA224_WITH_ECDSA_OID)) {
        return "SHA224withECDSA";
    }
    if (oid.equals(X9_SHA256_WITH_ECDSA_OID)) {
        return "SHA256withECDSA";
    }
    if (oid.equals(PKCS1_RSA_OID)) {
        return "RSA";
    }
    if (oid.equals(PKCS1_MD2_WITH_RSA_OID)) {
        return "MD2withRSA";
    }
    if (oid.equals(PKCS1_MD4_WITH_RSA_OID)) {
        return "MD4withRSA";
    }
    if (oid.equals(PKCS1_MD5_WITH_RSA_OID)) {
        return "MD5withRSA";
    }
    if (oid.equals(PKCS1_SHA1_WITH_RSA_OID)) {
        return "SHA1withRSA";
    }
    if (oid.equals(PKCS1_SHA256_WITH_RSA_OID)) {
        return "SHA256withRSA";
    }
    if (oid.equals(PKCS1_SHA384_WITH_RSA_OID)) {
        return "SHA384withRSA";
    }
    if (oid.equals(PKCS1_SHA512_WITH_RSA_OID)) {
        return "SHA512withRSA";
    }
    if (oid.equals(PKCS1_SHA224_WITH_RSA_OID)) {
        return "SHA224withRSA";
    }
    if (oid.equals(IEEE_P1363_SHA1_OID)) {
        return "SHA-1";
    }
    if (oid.equals(PKCS1_RSASSA_PSS_OID)) {
        return "SSAwithRSA/PSS";
    }
    if (oid.equals(PKCS1_SHA256_WITH_RSA_AND_MGF1)) {
        return "SHA256withRSAandMGF1";
    }
    throw new NoSuchAlgorithmException("Unknown OID " + oid);
}

From source file:org.jmrtd.lds.SignedDataUtil.java

License:Open Source License

public static String lookupOIDByMnemonic(String name) throws NoSuchAlgorithmException {
    if (name.equals("O")) {
        return X509ObjectIdentifiers.organization.getId();
    }// w  ww .ja  v a2  s  .  c om
    if (name.equals("OU")) {
        return X509ObjectIdentifiers.organizationalUnitName.getId();
    }
    if (name.equals("CN")) {
        return X509ObjectIdentifiers.commonName.getId();
    }
    if (name.equals("C")) {
        return X509ObjectIdentifiers.countryName.getId();
    }
    if (name.equals("ST")) {
        return X509ObjectIdentifiers.stateOrProvinceName.getId();
    }
    if (name.equals("L")) {
        return X509ObjectIdentifiers.localityName.getId();
    }
    if (name.equalsIgnoreCase("SHA-1") || name.equalsIgnoreCase("SHA1")) {
        return X509ObjectIdentifiers.id_SHA1.getId();
    }
    if (name.equalsIgnoreCase("SHA-224") || name.equalsIgnoreCase("SHA224")) {
        return NISTObjectIdentifiers.id_sha224.getId();
    }
    if (name.equalsIgnoreCase("SHA-256") || name.equalsIgnoreCase("SHA256")) {
        return NISTObjectIdentifiers.id_sha256.getId();
    }
    if (name.equalsIgnoreCase("SHA-384") || name.equalsIgnoreCase("SHA384")) {
        return NISTObjectIdentifiers.id_sha384.getId();
    }
    if (name.equalsIgnoreCase("SHA-512") || name.equalsIgnoreCase("SHA512")) {
        return NISTObjectIdentifiers.id_sha512.getId();
    }
    if (name.equalsIgnoreCase("RSA")) {
        return PKCS1_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD2withRSA")) {
        return PKCS1_MD2_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD4withRSA")) {
        return PKCS1_MD4_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD5withRSA")) {
        return PKCS1_MD5_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA1withRSA")) {
        return PKCS1_SHA1_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA256withRSA")) {
        return PKCS1_SHA256_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA384withRSA")) {
        return PKCS1_SHA384_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA512withRSA")) {
        return PKCS1_SHA512_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA224withRSA")) {
        return PKCS1_SHA224_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA1withECDSA")) {
        return X9_SHA1_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("SHA224withECDSA")) {
        return X9_SHA224_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("SHA256withECDSA")) {
        return X9_SHA256_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("SAwithRSA/PSS")) {
        return PKCS1_RSASSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SSAwithRSA/PSS")) {
        return PKCS1_RSASSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("RSASSA-PSS")) {
        return PKCS1_RSASSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SHA256withRSAandMGF1")) {
        return PKCS1_SHA256_WITH_RSA_AND_MGF1;
    }
    throw new NoSuchAlgorithmException("Unknown name " + name);
}

From source file:org.signserver.module.mrtdsodsigner.jmrtd.SODFile.java

License:Open Source License

/**
 * Gets the common mnemonic string (such as "SHA1", "SHA256withRSA") given an OID.
 *
 * @param oid a BC OID//from  www . j ava  2  s.  c  om
 *
 * @throws NoSuchAlgorithmException if the provided OID is not yet supported
 */
private static String lookupMnemonicByOID(DERObjectIdentifier oid) throws NoSuchAlgorithmException {
    if (oid.equals(X509ObjectIdentifiers.organization)) {
        return "O";
    }
    if (oid.equals(X509ObjectIdentifiers.organizationalUnitName)) {
        return "OU";
    }
    if (oid.equals(X509ObjectIdentifiers.commonName)) {
        return "CN";
    }
    if (oid.equals(X509ObjectIdentifiers.countryName)) {
        return "C";
    }
    if (oid.equals(X509ObjectIdentifiers.stateOrProvinceName)) {
        return "ST";
    }
    if (oid.equals(X509ObjectIdentifiers.localityName)) {
        return "L";
    }
    if (oid.equals(X509ObjectIdentifiers.id_SHA1)) {
        return "SHA1";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha224)) {
        return "SHA224";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha256)) {
        return "SHA256";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha384)) {
        return "SHA384";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha512)) {
        return "SHA512";
    }
    if (oid.equals(X9_SHA1_WITH_ECDSA_OID)) {
        return "SHA1withECDSA";
    }
    if (oid.equals(X9_SHA224_WITH_ECDSA_OID)) {
        return "SHA224withECDSA";
    }
    if (oid.equals(X9_SHA256_WITH_ECDSA_OID)) {
        return "SHA256withECDSA";
    }
    if (oid.equals(PKCS1_MGF1_OID)) {
        return "MGF1";
    }
    if (oid.equals(PKCS1_RSA_OID)) {
        return "RSA";
    }
    if (oid.equals(PKCS1_MD2_WITH_RSA_OID)) {
        return "MD2withRSA";
    }
    if (oid.equals(PKCS1_MD4_WITH_RSA_OID)) {
        return "MD4withRSA";
    }
    if (oid.equals(PKCS1_MD5_WITH_RSA_OID)) {
        return "MD5withRSA";
    }
    if (oid.equals(PKCS1_SHA1_WITH_RSA_OID)) {
        return "SHA1withRSA";
    }
    if (oid.equals(PKCS1_SHA256_WITH_RSA_OID)) {
        return "SHA256withRSA";
    }
    if (oid.equals(PKCS1_SHA384_WITH_RSA_OID)) {
        return "SHA384withRSA";
    }
    if (oid.equals(PKCS1_SHA512_WITH_RSA_OID)) {
        return "SHA512withRSA";
    }
    if (oid.equals(PKCS1_SHA224_WITH_RSA_OID)) {
        return "SHA224withRSA";
    }
    if (oid.equals(IEEE_P1363_SHA1_OID)) {
        return "SHA1";
    }
    if (oid.equals(PKCS1_RSA_PSS_OID)) {
        return "RSASSA-PSS";
    }
    throw new NoSuchAlgorithmException("Unknown OID " + oid);
}

From source file:org.signserver.module.mrtdsodsigner.jmrtd.SODFile.java

License:Open Source License

private static ASN1ObjectIdentifier lookupOIDByMnemonic(String name) throws NoSuchAlgorithmException {
    if (name.equals("O")) {
        return X509ObjectIdentifiers.organization;
    }//from   w ww .j  av  a2  s .c o  m
    if (name.equals("OU")) {
        return X509ObjectIdentifiers.organizationalUnitName;
    }
    if (name.equals("CN")) {
        return X509ObjectIdentifiers.commonName;
    }
    if (name.equals("C")) {
        return X509ObjectIdentifiers.countryName;
    }
    if (name.equals("ST")) {
        return X509ObjectIdentifiers.stateOrProvinceName;
    }
    if (name.equals("L")) {
        return X509ObjectIdentifiers.localityName;
    }
    if (name.equalsIgnoreCase("SHA1")) {
        return X509ObjectIdentifiers.id_SHA1;
    }
    if (name.equalsIgnoreCase("SHA224")) {
        return NISTObjectIdentifiers.id_sha224;
    }
    if (name.equalsIgnoreCase("SHA256")) {
        return NISTObjectIdentifiers.id_sha256;
    }
    if (name.equalsIgnoreCase("SHA384")) {
        return NISTObjectIdentifiers.id_sha384;
    }
    if (name.equalsIgnoreCase("SHA512")) {
        return NISTObjectIdentifiers.id_sha512;
    }
    if (name.equalsIgnoreCase("RSA")) {
        return PKCS1_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD2withRSA")) {
        return PKCS1_MD2_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD4withRSA")) {
        return PKCS1_MD4_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("MD5withRSA")) {
        return PKCS1_MD5_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA1withRSA")) {
        return PKCS1_SHA1_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA256withRSA")) {
        return PKCS1_SHA256_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA384withRSA")) {
        return PKCS1_SHA384_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA512withRSA")) {
        return PKCS1_SHA512_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA224withRSA")) {
        return PKCS1_SHA224_WITH_RSA_OID;
    }
    if (name.equalsIgnoreCase("SHA1withECDSA")) {
        return X9_SHA1_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("SHA224withECDSA")) {
        return X9_SHA224_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("SHA256withECDSA")) {
        return X9_SHA256_WITH_ECDSA_OID;
    }
    if (name.equalsIgnoreCase("MGF1")) {
        return PKCS1_MGF1_OID;
    }
    if (name.equalsIgnoreCase("SHA1withRSAandMGF1")) {
        return PKCS1_RSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SHA224withRSAandMGF1")) {
        return PKCS1_RSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SHA256withRSAandMGF1")) {
        return PKCS1_RSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SHA384withRSAandMGF1")) {
        return PKCS1_RSA_PSS_OID;
    }
    if (name.equalsIgnoreCase("SHA512withRSAandMGF1")) {
        return PKCS1_RSA_PSS_OID;
    }
    throw new NoSuchAlgorithmException("Unknown name " + name);
}

From source file:org.xipki.common.util.AlgorithmUtil.java

License:Open Source License

public static ASN1ObjectIdentifier getHashAlg(String hashAlgName) throws NoSuchAlgorithmException {
    hashAlgName = hashAlgName.trim();//  w w  w. ja  v  a  2  s. c  o  m
    ParamChecker.assertNotBlank("hashAlgName", hashAlgName);
    hashAlgName = hashAlgName.replace("-", "").toUpperCase();

    if ("SHA1".equalsIgnoreCase(hashAlgName)) {
        return X509ObjectIdentifiers.id_SHA1;
    } else if ("SHA224".equalsIgnoreCase(hashAlgName)) {
        return NISTObjectIdentifiers.id_sha224;
    } else if ("SHA256".equalsIgnoreCase(hashAlgName)) {
        return NISTObjectIdentifiers.id_sha256;
    } else if ("SHA384".equalsIgnoreCase(hashAlgName)) {
        return NISTObjectIdentifiers.id_sha384;
    } else if ("SHA512".equalsIgnoreCase(hashAlgName)) {
        return NISTObjectIdentifiers.id_sha512;
    } else {
        throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgName);
    }
}

From source file:org.xipki.common.util.AlgorithmUtil.java

License:Open Source License

static public AlgorithmIdentifier getSignatureAlgoId(final String signatureAlgoName)
        throws NoSuchAlgorithmException {
    String algoS = signatureAlgoName.replaceAll("-", "");

    AlgorithmIdentifier signatureAlgId;//  w w w. j  a  v a  2  s.  c o  m
    if ("SHA1withRSAandMGF1".equalsIgnoreCase(algoS) || "SHA224withRSAandMGF1".equalsIgnoreCase(algoS)
            || "SHA256withRSAandMGF1".equalsIgnoreCase(algoS) || "SHA384withRSAandMGF1".equalsIgnoreCase(algoS)
            || "SHA512withRSAandMGF1".equalsIgnoreCase(algoS)) {
        ASN1ObjectIdentifier hashAlgo;
        if ("SHA1withRSAandMGF1".equalsIgnoreCase(algoS)) {
            hashAlgo = X509ObjectIdentifiers.id_SHA1;
        } else if ("SHA224withRSAandMGF1".equalsIgnoreCase(algoS)) {
            hashAlgo = NISTObjectIdentifiers.id_sha224;
        } else if ("SHA256withRSAandMGF1".equalsIgnoreCase(algoS)) {
            hashAlgo = NISTObjectIdentifiers.id_sha256;
        } else if ("SHA384withRSAandMGF1".equalsIgnoreCase(algoS)) {
            hashAlgo = NISTObjectIdentifiers.id_sha384;
        } else if ("SHA512withRSAandMGF1".equalsIgnoreCase(algoS)) {
            hashAlgo = NISTObjectIdentifiers.id_sha512;
        } else {
            throw new NoSuchAlgorithmException("should not reach here, unknown algorithm " + algoS);
        }

        signatureAlgId = AlgorithmUtil.buildRSAPSSAlgorithmIdentifier(hashAlgo);
    } else {
        boolean withNullParam = false;
        ASN1ObjectIdentifier algOid;
        if ("SHA1withRSA".equalsIgnoreCase(algoS) || "RSAwithSHA1".equalsIgnoreCase(algoS)
                || PKCSObjectIdentifiers.sha1WithRSAEncryption.getId().equals(algoS)) {
            algOid = PKCSObjectIdentifiers.sha1WithRSAEncryption;
            withNullParam = true;
        } else if ("SHA224withRSA".equalsIgnoreCase(algoS) || "RSAwithSHA224".equalsIgnoreCase(algoS)
                || PKCSObjectIdentifiers.sha224WithRSAEncryption.getId().equals(algoS)) {
            algOid = PKCSObjectIdentifiers.sha224WithRSAEncryption;
            withNullParam = true;
        } else if ("SHA256withRSA".equalsIgnoreCase(algoS) || "RSAwithSHA256".equalsIgnoreCase(algoS)
                || PKCSObjectIdentifiers.sha256WithRSAEncryption.getId().equals(algoS)) {
            algOid = PKCSObjectIdentifiers.sha256WithRSAEncryption;
            withNullParam = true;
        } else if ("SHA384withRSA".equalsIgnoreCase(algoS) || "RSAwithSHA384".equalsIgnoreCase(algoS)
                || PKCSObjectIdentifiers.sha384WithRSAEncryption.getId().equals(algoS)) {
            algOid = PKCSObjectIdentifiers.sha384WithRSAEncryption;
            withNullParam = true;
        } else if ("SHA512withRSA".equalsIgnoreCase(algoS) || "RSAwithSHA512".equalsIgnoreCase(algoS)
                || PKCSObjectIdentifiers.sha512WithRSAEncryption.getId().equals(algoS)) {
            algOid = PKCSObjectIdentifiers.sha512WithRSAEncryption;
            withNullParam = true;
        } else if ("SHA1withECDSA".equalsIgnoreCase(algoS) || "ECDSAwithSHA1".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.ecdsa_with_SHA1.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.ecdsa_with_SHA1;
        } else if ("SHA224withECDSA".equalsIgnoreCase(algoS) || "ECDSAwithSHA224".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.ecdsa_with_SHA224.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.ecdsa_with_SHA224;
        } else if ("SHA256withECDSA".equalsIgnoreCase(algoS) || "ECDSAwithSHA256".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.ecdsa_with_SHA256.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.ecdsa_with_SHA256;
        } else if ("SHA384withECDSA".equalsIgnoreCase(algoS) || "ECDSAwithSHA384".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.ecdsa_with_SHA384.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.ecdsa_with_SHA384;
        } else if ("SHA512withECDSA".equalsIgnoreCase(algoS) || "ECDSAwithSHA512".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.ecdsa_with_SHA512.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.ecdsa_with_SHA512;
        } else if ("SHA1withPlainECDSA".equalsIgnoreCase(algoS) || "PlainECDSAwithSHA1".equalsIgnoreCase(algoS)
                || BSIObjectIdentifiers.ecdsa_plain_SHA1.getId().equals(algoS)) {
            algOid = BSIObjectIdentifiers.ecdsa_plain_SHA1;
        } else if ("SHA224withPlainECDSA".equalsIgnoreCase(algoS)
                || "PlainECDSAwithSHA224".equalsIgnoreCase(algoS)
                || BSIObjectIdentifiers.ecdsa_plain_SHA224.getId().equals(algoS)) {
            algOid = BSIObjectIdentifiers.ecdsa_plain_SHA224;
        } else if ("SHA256withPlainECDSA".equalsIgnoreCase(algoS)
                || "PlainECDSAwithSHA256".equalsIgnoreCase(algoS)
                || BSIObjectIdentifiers.ecdsa_plain_SHA256.getId().equals(algoS)) {
            algOid = BSIObjectIdentifiers.ecdsa_plain_SHA256;
        } else if ("SHA384withPlainECDSA".equalsIgnoreCase(algoS)
                || "PlainECDSAwithSHA384".equalsIgnoreCase(algoS)
                || BSIObjectIdentifiers.ecdsa_plain_SHA384.getId().equals(algoS)) {
            algOid = BSIObjectIdentifiers.ecdsa_plain_SHA384;
        } else if ("SHA512withPlainECDSA".equalsIgnoreCase(algoS)
                || "PlainECDSAwithSHA512".equalsIgnoreCase(algoS)
                || BSIObjectIdentifiers.ecdsa_plain_SHA512.getId().equals(algoS)) {
            algOid = BSIObjectIdentifiers.ecdsa_plain_SHA512;
        } else if ("SHA1withDSA".equalsIgnoreCase(algoS) || "DSAwithSHA1".equalsIgnoreCase(algoS)
                || X9ObjectIdentifiers.id_dsa_with_sha1.getId().equals(algoS)) {
            algOid = X9ObjectIdentifiers.id_dsa_with_sha1;
        } else if ("SHA224withDSA".equalsIgnoreCase(algoS) || "DSAwithSHA224".equalsIgnoreCase(algoS)
                || NISTObjectIdentifiers.dsa_with_sha224.getId().equals(algoS)) {
            algOid = NISTObjectIdentifiers.dsa_with_sha224;
        } else if ("SHA256withDSA".equalsIgnoreCase(algoS) || "DSAwithSHA256".equalsIgnoreCase(algoS)
                || NISTObjectIdentifiers.dsa_with_sha256.getId().equals(algoS)) {
            algOid = NISTObjectIdentifiers.dsa_with_sha256;
        } else if ("SHA384withDSA".equalsIgnoreCase(algoS) || "DSAwithSHA384".equalsIgnoreCase(algoS)
                || NISTObjectIdentifiers.dsa_with_sha384.getId().equals(algoS)) {
            algOid = NISTObjectIdentifiers.dsa_with_sha384;
        } else if ("SHA512withDSA".equalsIgnoreCase(algoS) || "DSAwithSHA512".equalsIgnoreCase(algoS)
                || NISTObjectIdentifiers.dsa_with_sha512.getId().equals(algoS)) {
            algOid = NISTObjectIdentifiers.dsa_with_sha512;
        } else {
            throw new NoSuchAlgorithmException("unsupported signature algorithm " + algoS);
        }

        signatureAlgId = withNullParam ? new AlgorithmIdentifier(algOid, DERNull.INSTANCE)
                : new AlgorithmIdentifier(algOid);
    }

    return signatureAlgId;
}