Example usage for org.bouncycastle.asn1.x509 X509ObjectIdentifiers commonName

List of usage examples for org.bouncycastle.asn1.x509 X509ObjectIdentifiers commonName

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 X509ObjectIdentifiers commonName.

Prototype

ASN1ObjectIdentifier commonName

To view the source code for org.bouncycastle.asn1.x509 X509ObjectIdentifiers commonName.

Click Source Link

Document

Subject RDN components: commonName = 2.5.4.3

Usage

From source file:com.adaptris.core.security.JunitSecurityHelper.java

License:Apache License

private static CertificateBuilder getBuilder(String commonName) throws Exception {

    CertificateBuilder builder = CertificateBuilderFactory.getInstance().createBuilder();
    CertificateParameter cp = new CertificateParameter();
    X500NameBuilder subject = new X500NameBuilder();
    subject.addRDN(X509ObjectIdentifiers.countryName, "GB");
    subject.addRDN(X509ObjectIdentifiers.stateOrProvinceName, "Middlesex");
    subject.addRDN(X509ObjectIdentifiers.localityName, "Uxbridge");
    subject.addRDN(X509ObjectIdentifiers.organization, "Adaptris");
    subject.addRDN(X509ObjectIdentifiers.organizationalUnitName, "JUNIT");
    subject.addRDN(X509ObjectIdentifiers.commonName, commonName);
    subject.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "myname@adaptris.com");

    cp.setSignatureAlgorithm("SHA256WithRSAEncryption");
    // Changed to 1024 as the key size, otherwise jdk8_66 appears to have a fit
    // wrt to java.security limiting the certpath algorithms
    // jdk.certpath.disabledAlgorithms=MD2, RSA keySize < 1024 (it was like this in _40, but doesn't
    // apparently break things
    cp.setKeyAlgorithm("RSA", 1024);
    cp.setSubjectInfo(subject.build());//from  ww w  .j  a  v  a2 s. co  m
    builder.setCertificateParameters(cp);
    return builder;
}

From source file:com.adaptris.security.Config.java

License:Apache License

public CertificateBuilder getBuilder(String commonName) throws Exception {

    CertificateBuilder builder = CertificateBuilderFactory.getInstance().createBuilder();
    CertificateParameter cp = new CertificateParameter();
    X500NameBuilder subject = new X500NameBuilder();

    subject.addRDN(X509ObjectIdentifiers.countryName, config.getProperty(CERTIFICATE_C));
    subject.addRDN(X509ObjectIdentifiers.stateOrProvinceName, config.getProperty(CERTIFICATE_ST));
    subject.addRDN(X509ObjectIdentifiers.localityName, config.getProperty(CERTIFICATE_L));
    subject.addRDN(X509ObjectIdentifiers.organization, config.getProperty(CERTIFICATE_O));
    subject.addRDN(X509ObjectIdentifiers.organizationalUnitName, config.getProperty(CERTIFICATE_OU));
    subject.addRDN(X509ObjectIdentifiers.commonName, commonName);
    subject.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, config.getProperty(CERTIFICATE_EMAIL));

    cp.setSignatureAlgorithm(config.getProperty(CERTIFICATE_SIGALG));

    cp.setKeyAlgorithm(config.getProperty(CERTIFICATE_KEYALG),
            Integer.parseInt(config.getProperty(CERTIFICATE_KEYSIZE)));
    cp.setSubjectInfo(subject.build());//from   w ww. ja  va  2  s.  c  om

    builder.setCertificateParameters(cp);
    return builder;
}

From source file:net.jsign.pe.PEFile.java

License:Apache License

/**
 * Print detailed informations about the PE file.
 *///from w  w  w .  j av  a 2 s .  co m
public void printInfo(PrintWriter out) {
    out.println("PE File");
    out.println("  Name:          " + raf.getName());
    out.println("  Size:          " + raf.length());
    out.println("  Last Modified: " + new Date(raf.lastModified()));
    out.println();

    out.println("PE Header");
    out.println("  Machine:                    " + getMachineType());
    out.println("  Number of sections:         " + getNumberOfSections());
    out.println("  Timestamp:                  " + getTimeDateStamp());
    out.println("  Pointer to symbol table:    0x" + Long.toHexString(getPointerToSymbolTable()));
    out.println("  Number of symbols:          " + getNumberOfSymbols());
    out.println("  Size of optional header:    " + getSizeOfOptionalHeader());
    out.println("  Characteristics:            0x" + Long.toBinaryString(getCharacteristics()));
    out.println();

    out.println("Optional Header");
    PEFormat format = getFormat();
    out.println(
            "  PE Format:                  0x" + Integer.toHexString(format.value) + " (" + format.label + ")");
    out.println("  Linker version:             " + getMajorLinkerVersion() + "." + getMinorLinkerVersion());
    out.println("  Size of code:               " + getSizeOfCode());
    out.println("  Size of initialized data:   " + getSizeOfInitializedData());
    out.println("  Size of uninitialized data: " + getSizeOfUninitializedData());
    out.println("  Address of entry point:     0x" + Long.toHexString(getAddressOfEntryPoint()));
    out.println("  Base of code:               0x" + Long.toHexString(getBaseOfCode()));
    if (PEFormat.PE32.equals(getFormat())) {
        out.println("  Base of data:               0x" + Long.toHexString(getBaseOfData()));
    }
    out.println("  Image base:                 0x" + Long.toHexString(getImageBase()));
    out.println("  Section alignment:          " + getSectionAlignment());
    out.println("  File alignment:             " + getFileAlignment());
    out.println("  Operating system version:   " + getMajorOperatingSystemVersion() + "."
            + getMinorOperatingSystemVersion());
    out.println("  Image version:              " + getMajorImageVersion() + "." + getMinorImageVersion());
    out.println(
            "  Subsystem version:          " + getMajorSubsystemVersion() + "." + getMinorSubsystemVersion());
    out.println("  Size of image:              " + getSizeOfImage());
    out.println("  Size of headers:            " + getSizeOfHeaders());
    out.println("  Checksum:                   0x" + Long.toHexString(getCheckSum()));
    out.println("  Checksum (computed):        0x" + Long.toHexString(computeChecksum()));
    out.println("  Subsystem:                  " + getSubsystem());
    out.println("  DLL characteristics:        0x" + Long.toBinaryString(getDllCharacteristics()));
    out.println("  Size of stack reserve:      " + getSizeOfStackReserve());
    out.println("  Size of stack commit:       " + getSizeOfStackCommit());
    out.println("  Size of heap reserve:       " + getSizeOfHeapReserve());
    out.println("  Size of heap commit:        " + getSizeOfHeapCommit());
    out.println("  Number of RVA and sizes:    " + getNumberOfRvaAndSizes());
    out.println();

    out.println("Data Directory");
    for (DataDirectoryType type : DataDirectoryType.values()) {
        DataDirectory entry = getDataDirectory(type);
        if (entry != null && entry.getVirtualAddress() != 0) {
            out.printf("  %-30s 0x%08x %8d bytes\n", type, entry.getVirtualAddress(), entry.getSize());
        }
    }
    out.println();

    int sectionTableOffset = getDataDirectoryOffset() + 8 * getNumberOfRvaAndSizes();
    out.println("Sections");
    out.println("      Name     Virtual Size  Virtual Address  Raw Data Size  Raw Data Ptr  Characteristics");
    for (int i = 0; i < getNumberOfSections(); i++) {
        Section section = new Section(this, sectionTableOffset + 40 * i);
        out.printf("  #%d  %-8s     %8d       0x%08x       %8d    0x%08x  %s\n", i + 1, section.getName(),
                section.getVirtualSize(), section.getVirtualAddress(), section.getSizeOfRawData(),
                section.getPointerToRawData(), section.getCharacteristics());
    }
    out.println();

    List<CMSSignedData> signatures = getSignatures();
    if (!signatures.isEmpty()) {
        out.println("Signatures");
        for (CMSSignedData signedData : signatures) {
            SignerInformation signerInformation = signedData.getSignerInfos().getSigners().iterator().next();
            X509CertificateHolder certificate = (X509CertificateHolder) signedData.getCertificates()
                    .getMatches(signerInformation.getSID()).iterator().next();

            String commonName = certificate.getSubject().getRDNs(X509ObjectIdentifiers.commonName)[0].getFirst()
                    .getValue().toString();

            AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
            boolean timestamped = unsignedAttributes != null
                    && (unsignedAttributes.get(PKCSObjectIdentifiers.pkcs_9_at_counterSignature) != null
                            || unsignedAttributes.get(AuthenticodeObjectIdentifiers.SPC_RFC3161_OBJID) != null);
            DigestAlgorithm algorithm = DigestAlgorithm
                    .of(signerInformation.getDigestAlgorithmID().getAlgorithm());
            out.println("  " + commonName + "  " + (algorithm != null ? "[" + algorithm.id + "]  " : "")
                    + (timestamped ? "(timestamped)" : ""));
        }
    }
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get extension value as a string.//w ww. j a  va 2s  .  co  m
 * 
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 * @throws ParseException If a date formatting problem occurs
 */
public String getStringValue() throws IOException, ParseException {
    // Get octet string from extension
    byte[] bOctets = ((ASN1OctetString) ASN1Primitive.fromByteArray(m_bValue)).getOctets();

    // Octet string processed differently depending on extension type
    if (m_Oid.equals(X509ObjectIdentifiers.commonName)) {
        return getCommonNameStringValue(bOctets);
    } else if (m_Oid.equals(Extension.subjectKeyIdentifier)) {
        return getSubjectKeyIdentifierStringValue(bOctets);
    } else if (m_Oid.equals(Extension.keyUsage)) {
        return getKeyUsageStringValue(bOctets);
    } else if (m_Oid.equals(Extension.privateKeyUsagePeriod)) {
        return getPrivateKeyUsagePeriod(bOctets);
    } else if (m_Oid.equals(Extension.issuerAlternativeName)
            || m_Oid.equals(Extension.subjectAlternativeName)) {
        return getAlternativeName(bOctets);
    } else if (m_Oid.equals(Extension.basicConstraints)) {
        return getBasicConstraintsStringValue(bOctets);
    } else if (m_Oid.equals(Extension.cRLNumber)) {
        return getCrlNumberStringValue(bOctets);
    } else if (m_Oid.equals(Extension.reasonCode)) {
        return getReasonCodeStringValue(bOctets);
    } else if (m_Oid.equals(Extension.instructionCode)) {
        return getHoldInstructionCodeStringValue(bOctets);
    } else if (m_Oid.equals(Extension.invalidityDate)) {
        return getInvalidityDateStringValue(bOctets);
    } else if (m_Oid.equals(Extension.deltaCRLIndicator)) {
        return getDeltaCrlIndicatorStringValue(bOctets);
    } else if (m_Oid.equals(Extension.certificateIssuer)) {
        return getCertificateIssuerStringValue(bOctets);
    } else if (m_Oid.equals(Extension.policyMappings)) {
        return getPolicyMappingsStringValue(bOctets);
    } else if (m_Oid.equals(Extension.authorityKeyIdentifier)) {
        return getAuthorityKeyIdentifierStringValue(bOctets);
    } else if (m_Oid.equals(Extension.policyConstraints)) {
        return getPolicyConstraintsStringValue(bOctets);
    } else if (m_Oid.equals(Extension.extendedKeyUsage)) {
        return getExtendedKeyUsageStringValue(bOctets);
    } else if (m_Oid.equals(Extension.inhibitAnyPolicy)) {
        return getInhibitAnyPolicyStringValue(bOctets);
    } else if (m_Oid.equals(MiscObjectIdentifiers.entrustVersionExtension)) {
        return getEntrustVersionExtensionStringValue(bOctets);
    } else if (m_Oid.equals(PKCSObjectIdentifiers.pkcs_9_at_smimeCapabilities)) {
        return getSmimeCapabilitiesStringValue(bOctets);
    } else if (m_Oid.equals(MicrosoftObjectIdentifiers.microsoftCaVersion)) {
        return getMicrosoftCAVersionStringValue(bOctets);
    } else if (m_Oid.equals(MicrosoftObjectIdentifiers.microsoftPrevCaCertHash)) {
        return getMicrosoftPreviousCACertificateHashStringValue(bOctets);
    } else if (m_Oid.equals(MicrosoftObjectIdentifiers.microsoftCertTemplateV2)) {
        return getMicrosoftCertificateTemplateV2StringValue(bOctets);
    } else if (m_Oid.equals(MicrosoftObjectIdentifiers.microsoftAppPolicies)) {
        return getUnknownOidStringValue(bOctets); // TODO
    }
    // TODO: https://github.com/bcgit/bc-java/pull/92
    else if (m_Oid.toString().equals("1.3.6.1.4.1.311.21.4")) {
        return getMicrosoftCrlNextPublish(bOctets);
    } else if (m_Oid.equals(Extension.authorityInfoAccess) || m_Oid.equals(Extension.subjectInfoAccess)) {
        return getInformationAccessStringValue(bOctets);
    } else if (m_Oid.equals(Extension.logoType)) {
        return getLogotypeStringValue(bOctets);
    } else if (m_Oid.equals(MiscObjectIdentifiers.novellSecurityAttribs)) {
        return getNovellSecurityAttributesStringValue(bOctets);
    } else if (m_Oid.equals(MiscObjectIdentifiers.netscapeCertType)) {
        return getNetscapeCertificateTypeStringValue(bOctets);
    } else if (m_Oid.equals(MiscObjectIdentifiers.netscapeSSLServerName)
            || m_Oid.equals(MiscObjectIdentifiers.netscapeCertComment)
            || m_Oid.equals(MiscObjectIdentifiers.verisignDnbDunsNumber)
            || m_Oid.equals(MicrosoftObjectIdentifiers.microsoftCertTemplateV1)) {
        return getASN1ObjectString(bOctets);
    } else if (m_Oid.equals(MiscObjectIdentifiers.netscapeCApolicyURL)) {
        return getNetscapeExtensionURLValue(bOctets, LinkClass.BROWSER);
    } else if (m_Oid.equals(MiscObjectIdentifiers.netscapeBaseURL)
            || m_Oid.equals(MiscObjectIdentifiers.netscapeRenewalURL)
            || m_Oid.equals(MiscObjectIdentifiers.netscapeRevocationURL)
            || m_Oid.equals(MiscObjectIdentifiers.netscapeCARevocationURL)) {
        return getNetscapeExtensionURLValue(bOctets, LinkClass.CRL);
    } else if (m_Oid.equals(Extension.cRLDistributionPoints)) {
        return getCrlDistributionPointsStringValue(bOctets);
    } else if (m_Oid.equals(Extension.certificatePolicies)) {
        return getCertificatePoliciesStringValue(bOctets);
    }

    // TODO:
    // - CERTIFICATE_POLICIES_OLD_OID
    // - AUTHORITY_KEY_IDENTIFIER_OLD_OID
    // - BASIC_CONSTRAINTS_OLD_0_OID

    // Don't know how to process the extension
    // and clear text
    else {
        return getUnknownOidStringValue(bOctets);
    }
}

From source file:org.cesecore.certificates.ca.X509CATest.java

License:Open Source License

/**
 * Tests default value of "use printable string" option (should be disabled by default)
 * and tests that the option works.//from ww  w .  j  a  v  a 2  s.com
 */
@Test
public void testPrintableString() throws Exception {
    final CryptoToken cryptoToken = getNewCryptoToken();
    final String caDN = "CN=foo CA,O=Bar,JurisdictionCountry=DE,JurisdictionState=Stockholm,JurisdictionLocality=Solna,C=SE";
    final X509CA testCa = createTestCA(cryptoToken, caDN);
    assertFalse("\"Use Printable String\" should be turned off by default",
            testCa.getUsePrintableStringSubjectDN());

    Certificate cert = testCa.getCACertificate();
    assertTrue("Certificate CN was not UTF-8 encoded by default.",
            getValueFromDN(cert, X509ObjectIdentifiers.commonName) instanceof DERUTF8String);
    assertTrue("Certificate C was not PrintableString encoded.",
            getValueFromDN(cert, X509ObjectIdentifiers.countryName) instanceof DERPrintableString); // C is always PrintableString

    // Test generation by calling generateCertificate directly
    final String subjectDN = "CN=foo subject,O=Bar,JurisdictionCountry=DE,JurisdictionState=Stockholm,JurisdictionLocality=Solna,C=SE";
    final EndEntityInformation subject = new EndEntityInformation("testPrintableString", subjectDN,
            testCa.getCAId(), null, null, new EndEntityType(EndEntityTypes.ENDUSER), 0, 0,
            EndEntityConstants.TOKEN_USERGEN, 0, null);
    final CertificateProfile certProfile = new CertificateProfile(
            CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER);
    cert = testCa.generateCertificate(cryptoToken, subject, cert.getPublicKey(),
            KeyUsage.digitalSignature | KeyUsage.keyEncipherment, null, 30, certProfile, null);
    assertTrue("Certificate CN was not UTF-8 encoded by default.",
            getValueFromDN(cert, X509ObjectIdentifiers.commonName) instanceof DERUTF8String);
    assertTrue("Certificate O was not UTF-8 encoded by default.",
            getValueFromDN(cert, X509ObjectIdentifiers.organization) instanceof DERUTF8String);
    assertTrue("Certificate JurisdictionState was not UTF-8 encoded.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_STATE) instanceof DERUTF8String);
    assertTrue("Certificate JurisdictionLocality was not UTF-8 encoded.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_LOCALITY) instanceof DERUTF8String);
    assertTrue("Certificate C was not PrintableString encoded.",
            getValueFromDN(cert, X509ObjectIdentifiers.countryName) instanceof DERPrintableString); // C is always PrintableString
    assertTrue("Certificate JurisdictionCountry was not PrintableString encoded.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_COUNTRY) instanceof DERPrintableString); // C is always PrintableString

    // Now generate a new certificate with a PrintableString-encoded DN
    testCa.setUsePrintableStringSubjectDN(true);
    cert = testCa.generateCertificate(cryptoToken, subject, cert.getPublicKey(),
            KeyUsage.digitalSignature | KeyUsage.keyEncipherment, null, 30, certProfile, null);
    assertTrue("Certificate CN was not encoded as PrintableString.",
            getValueFromDN(cert, X509ObjectIdentifiers.commonName) instanceof DERPrintableString);
    assertTrue("Certificate O was not encoded as PrintableString.",
            getValueFromDN(cert, X509ObjectIdentifiers.organization) instanceof DERPrintableString);
    assertTrue("Certificate JurisdictionState was not encoded as PrintableString.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_STATE) instanceof DERPrintableString);
    assertTrue("Certificate JurisdictionLocality was not encoded as PrintableString.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_LOCALITY) instanceof DERPrintableString);
    assertTrue("Certificate C was not PrintableString encoded.",
            getValueFromDN(cert, X509ObjectIdentifiers.countryName) instanceof DERPrintableString); // C is always PrintableString
    assertTrue("Certificate JurisdictionCountry was not PrintableString encoded.",
            getValueFromDN(cert, CeSecoreNameStyle.JURISDICTION_COUNTRY) instanceof DERPrintableString); // C is always PrintableString
}

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/*from   w ww. j a va 2s .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();
    }/*from w w  w .  jav a2s .c  o m*/
    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 ww  w. jav  a  2  s. co  m
 *
 * @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  w  w  .j  a  v a  2  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:passwdmanager.hig.no.lds.DG_SOD.java

/**
 * Gets the common mnemonic string (such as "SHA1", "SHA256withRSA") given
 * an OID.//from   ww w .jav a2 s  .co  m
 * 
 * @param oid
 *            a BC OID
 * 
 * @throws NoSuchAlgorithmException
 *             if the provided OID is not yet supported
 */
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(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";
    }
    throw new NoSuchAlgorithmException("Unknown OID " + oid);
}