當前位置: 首頁>>代碼示例>>Java>>正文


Java X500NameBuilder類代碼示例

本文整理匯總了Java中org.bouncycastle.asn1.x500.X500NameBuilder的典型用法代碼示例。如果您正苦於以下問題:Java X500NameBuilder類的具體用法?Java X500NameBuilder怎麽用?Java X500NameBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


X500NameBuilder類屬於org.bouncycastle.asn1.x500包,在下文中一共展示了X500NameBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildName

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
static X500Name buildName(String commonName, String organization, String organizationUnit, String locality,
                          String state, String country) {

    X500NameBuilder nameBuilder = new X500NameBuilder();

    if (!commonName.isEmpty()) {
        nameBuilder.addRDN(BCStyle.CN, commonName);
    }
    if (!organizationUnit.isEmpty()) {
        nameBuilder.addRDN(BCStyle.OU, organizationUnit);
    }
    if (!organization.isEmpty()) {
        nameBuilder.addRDN(BCStyle.O, organization);
    }
    if (!locality.isEmpty()) {
        nameBuilder.addRDN(BCStyle.L, locality);
    }
    if (!state.isEmpty()) {
        nameBuilder.addRDN(BCStyle.ST, state);
    }
    if (!country.isEmpty()) {
        nameBuilder.addRDN(BCStyle.C, country);
    }

    return nameBuilder.build();
}
 
開發者ID:stevanmilic,項目名稱:X509-certificate-manager,代碼行數:27,代碼來源:CertificateHelper.java

示例2: createCertificateBuilder

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private X509v3CertificateBuilder createCertificateBuilder(KeyPair keyPair) throws PropertyConfigurationException, CertIOException {
    X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
    nameBuilder.addRDN(BCStyle.CN, propertyConfigurationService.getConfigValue(CERT_COMMON_NAME_PROPERTY));
    nameBuilder.addRDN(BCStyle.O, propertyConfigurationService.getConfigValue(CERT_ORGANISATION_PROPERTY));
    nameBuilder.addRDN(BCStyle.OU, propertyConfigurationService.getConfigValue(CERT_ORGANISATIONAL_UNIT_PROPERTY));
    nameBuilder.addRDN(BCStyle.C, propertyConfigurationService.getConfigValue(CERT_COUNTRY_PROPERTY));
    X500Name x500Name = nameBuilder.build();

    BigInteger serial = new BigInteger(CERT_SERIAL_NUMBER_BIT_SIZE, SecureRandomFactory.createPRNG());

    SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());

    Date startDate = new Date();
    Date endDate = Date.from(startDate.toInstant().plus(propertyConfigurationService.getConfigValueAsInt(CERT_VALIDITY_DAYS_PROPERTY), ChronoUnit.DAYS));

    X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(x500Name, serial, startDate, endDate, x500Name, publicKeyInfo);

    String certFriendlyName = propertyConfigurationService.getConfigValue(CERT_PRIVATE_FRIENDLY_NAME_PROPERTY);
    certificateBuilder.addExtension(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, false, new DERBMPString(certFriendlyName));
    return certificateBuilder;
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-1-0,代碼行數:22,代碼來源:KeyGenerator.java

示例3: x500Name

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
public X500Name x500Name() throws IOException {
	if(name==null) {
		X500NameBuilder xnb = new X500NameBuilder();
		xnb.addRDN(BCStyle.CN,cn);
		xnb.addRDN(BCStyle.E,email);
		if(environment==null) {
			xnb.addRDN(BCStyle.OU,mechID);
		} else {
			xnb.addRDN(BCStyle.OU,mechID+':'+environment);
		}
		xnb.addRDN(BCStyle.O,o);
		xnb.addRDN(BCStyle.L,l);
		xnb.addRDN(BCStyle.ST,st);
		xnb.addRDN(BCStyle.C,c);
		name = xnb.build();
	}
	return name;
}
 
開發者ID:att,項目名稱:AAF,代碼行數:19,代碼來源:CSRMeta.java

示例4: getSubject

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
/**
 * Returns a Subject for service certificate.
 */
public X500Name getSubject() {
    // Create subject CN as pod-name-0-task-name.service-name
    String cn = String.format("%s.%s",
            EndpointUtils.removeSlashes(EndpointUtils.replaceDotsWithDashes(taskInstanceName)),
            EndpointUtils.removeSlashes(EndpointUtils.replaceDotsWithDashes(serviceName)));

    if (cn.length() > CN_MAX_LENGTH) {
        cn = cn.substring(cn.length() - CN_MAX_LENGTH);
    }

    return new X500NameBuilder()
            .addRDN(BCStyle.CN, cn)
            .addRDN(BCStyle.O, "Mesosphere, Inc")
            .addRDN(BCStyle.L, "San Francisco")
            .addRDN(BCStyle.ST, "CA")
            .addRDN(BCStyle.C, "US")
            .build();
}
 
開發者ID:mesosphere,項目名稱:dcos-commons,代碼行數:22,代碼來源:CertificateNamesGenerator.java

示例5: generateCSR

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
public PKCS10CertificationRequest generateCSR(User user, KeyPair key) throws OperatorCreationException {
    X500Name x500User = new X500NameBuilder()
            .addRDN(BCStyle.C, user.getCountryName())
            .addRDN(BCStyle.ST, user.getProvinceName())
            .addRDN(BCStyle.L,  user.getLocalityName())
            .addRDN(BCStyle.O,  user.getOrganizationName())
            .addRDN(BCStyle.OU, user.getOrganizationUnitName())
            .addRDN(BCStyle.CN, user.getCommonName())
            .addRDN(BCStyle.EmailAddress, user.getEmailAddress())
            .build();
    PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
            x500User, key.getPublic());
    user.setPrivateKey(key.getPrivate().getEncoded());
    JcaContentSignerBuilder csBuilder= new JcaContentSignerBuilder("SHA512WithRSAEncryption");
    ContentSigner signer = csBuilder.build(key.getPrivate());
    return p10Builder.build(signer);
}
 
開發者ID:kawasima,項目名稱:occupy-pub,代碼行數:18,代碼來源:CertificationAuthority.java

示例6: generateCSR

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
public static PKCS10CertificationRequest generateCSR(String[] commonNames, KeyPair pair) throws OperatorCreationException, IOException {
	X500NameBuilder namebuilder = new X500NameBuilder(X500Name.getDefaultStyle());
	namebuilder.addRDN(BCStyle.CN, commonNames[0]);
	
	List<GeneralName> subjectAltNames = new ArrayList<>(commonNames.length);
	for (String cn:commonNames)
		subjectAltNames.add(new GeneralName(GeneralName.dNSName, cn));
	GeneralNames subjectAltName = new GeneralNames(subjectAltNames.toArray(new GeneralName[0]));         
	
	ExtensionsGenerator extGen = new ExtensionsGenerator();
	extGen.addExtension(Extension.subjectAlternativeName, false, subjectAltName.toASN1Primitive());
	
	PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(namebuilder.build(), pair.getPublic());
	p10Builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extGen.generate());
	JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA");
	ContentSigner signer = csBuilder.build(pair.getPrivate());
	PKCS10CertificationRequest request = p10Builder.build(signer);
	return request;
}
 
開發者ID:zero11it,項目名稱:acme-client,代碼行數:20,代碼來源:X509Utils.java

示例7: setOID

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private static void setOID(X500NameBuilder dnBuilder, X509Metadata metadata,
                           String oid, String defaultValue) {

    String value = null;
    if (metadata.oids != null && metadata.oids.containsKey(oid)) {
        value = metadata.oids.get(oid);
    }
    if (Strings.isNullOrEmpty(value)) {
        value = defaultValue;
    }

    if (!Strings.isNullOrEmpty(value)) {
        try {
            Field field = BCStyle.class.getField(oid);
            ASN1ObjectIdentifier objectId = (ASN1ObjectIdentifier) field.get(null);
            dnBuilder.addRDN(objectId, value);
        } catch (Exception e) {
            logger.error(MessageFormat.format("Failed to set OID \"{0}\"!", oid), e);
        }
    }
}
 
開發者ID:gitblit,項目名稱:fathom,代碼行數:22,代碼來源:X509Utils.java

示例8: generateCertSignRequest

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
/**
 * This method creates the PKCS10 Certificate Sign Request which is to be sent to the SCEP Server using the
 * generated PublicKey of the client. The certificate parameters used here are the ones from the AgentManager
 * which are the values read from the configurations file.
 *
 * @return the PKCS10CertificationRequest object created using the client specific configs and the generated
 * PublicKey
 * @throws AgentCoreOperationException if an error occurs when creating a content signer to sign the CSR.
 */
private PKCS10CertificationRequest generateCertSignRequest() throws AgentCoreOperationException {
    // Build the CN for the cert we are requesting.
    X500NameBuilder nameBld = new X500NameBuilder(BCStyle.INSTANCE);
    nameBld.addRDN(BCStyle.CN, AgentManager.getInstance().getAgentConfigs().getDeviceName());
    nameBld.addRDN(BCStyle.O, AgentManager.getInstance().getAgentConfigs().getDeviceOwner());
    nameBld.addRDN(BCStyle.OU, AgentManager.getInstance().getAgentConfigs().getDeviceOwner());
    nameBld.addRDN(BCStyle.UNIQUE_IDENTIFIER, AgentManager.getInstance().getAgentConfigs().getDeviceId());
    X500Name principal = nameBld.build();

    JcaContentSignerBuilder contentSignerBuilder = new JcaContentSignerBuilder(SIGNATURE_ALG).setProvider(PROVIDER);
    ContentSigner contentSigner;

    try {
        contentSigner = contentSignerBuilder.build(this.privateKey);
    } catch (OperatorCreationException e) {
        String errorMsg = "Could not create content signer with private key.";
        log.error(errorMsg);
        throw new AgentCoreOperationException(errorMsg, e);
    }

    // Generate the certificate signing request (csr = PKCS10)
    PKCS10CertificationRequestBuilder reqBuilder = new JcaPKCS10CertificationRequestBuilder(principal,
                                                                                            this.publicKey);
    return reqBuilder.build(contentSigner);
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-agents,代碼行數:35,代碼來源:EnrollmentManager.java

示例9: createX509V3Certificate

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
/**
 * Creates an X509 version3 certificate.
 *
 * @param kp           KeyPair that keeps the public and private keys for the new certificate.
 * @param days       time to live
 * @param issuerCommonName     Issuer CN string
 * @param subjectCommonName    Subject CN string
 * @param domain       Domain of the server.
 * @param signAlgoritm Signature algorithm. This can be either a name or an OID.
 * @return X509 V3 Certificate
 * @throws GeneralSecurityException
 * @throws IOException
 */
public static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, String issuerCommonName,
                                                                    String subjectCommonName, String domain,
                                                                    String signAlgoritm)
        throws GeneralSecurityException, IOException {

    // subjectDN
    X500NameBuilder subjectBuilder = new X500NameBuilder();
    subjectBuilder.addRDN(BCStyle.CN, subjectCommonName);

    // issuerDN
    X500NameBuilder issuerBuilder = new X500NameBuilder();
    issuerBuilder.addRDN(BCStyle.CN, issuerCommonName);

    return createX509V3Certificate(kp, days, issuerBuilder, subjectBuilder, domain, signAlgoritm);
}
 
開發者ID:igniterealtime,項目名稱:Openfire,代碼行數:29,代碼來源:CertificateManager.java

示例10: generateKey

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private Pair<Key, X509Certificate> generateKey(String name)
        throws GeneralSecurityException, OperatorCreationException {
    logger.debug("generating self-signed cert for {}", name);
    BouncyCastleProvider provider = new BouncyCastleProvider();
    Security.addProvider(provider);
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", provider);
    kpGen.initialize(1024, new SecureRandom());
    KeyPair pair = kpGen.generateKeyPair();
    X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);
    builder.addRDN(BCStyle.OU, "None");
    builder.addRDN(BCStyle.O, "None");
    builder.addRDN(BCStyle.CN, name);
    Instant now = Instant.now();
    Date notBefore = Date.from(now);
    Date notAfter = Date.from(now.plus(365, ChronoUnit.DAYS));
    BigInteger serial = BigInteger.valueOf(now.getEpochSecond());
    X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(builder.build(), serial, notBefore, notAfter,
            builder.build(), pair.getPublic());
    ContentSigner sigGen = new JcaContentSignerBuilder("SHA256WithRSAEncryption")
            .setProvider(provider)
            .build(pair.getPrivate());
    X509Certificate cert = new JcaX509CertificateConverter()
            .setProvider(provider)
            .getCertificate(certGen.build(sigGen));
    return Pair.of(pair.getPrivate(), cert);
}
 
開發者ID:bouncestorage,項目名稱:bouncestorage,代碼行數:27,代碼來源:KeyStoreUtils.java

示例11: generationTest

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private void generationTest(int keySize, String keyName, String sigName, String provider)
    throws Exception
{
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyName, "BC");

    kpg.initialize(keySize);

    KeyPair kp = kpg.genKeyPair();


    X500NameBuilder x500NameBld = new X500NameBuilder(BCStyle.INSTANCE);

    x500NameBld.addRDN(BCStyle.C, "AU");
    x500NameBld.addRDN(BCStyle.O, "The Legion of the Bouncy Castle");
    x500NameBld.addRDN(BCStyle.L, "Melbourne");
    x500NameBld.addRDN(BCStyle.ST, "Victoria");
    x500NameBld.addRDN(BCStyle.EmailAddress, "[email protected]");

    X500Name    subject = x500NameBld.build();

    PKCS10CertificationRequestBuilder requestBuilder = new JcaPKCS10CertificationRequestBuilder(subject, kp.getPublic());
                        
    PKCS10CertificationRequest req1 = requestBuilder.build(new JcaContentSignerBuilder(sigName).setProvider(provider).build(kp.getPrivate()));

    JcaPKCS10CertificationRequest req2 = new JcaPKCS10CertificationRequest(req1.getEncoded()).setProvider(provider);

    if (!req2.isSignatureValid(new JcaContentVerifierProviderBuilder().setProvider(provider).build(kp.getPublic())))
    {
        fail(sigName + ": Failed verify check.");
    }

    if (!Arrays.areEqual(req2.getPublicKey().getEncoded(), req1.getSubjectPublicKeyInfo().getEncoded()))
    {
        fail(keyName + ": Failed public key check.");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:37,代碼來源:PKCS10Test.java

示例12: setOID

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private static void setOID(X500NameBuilder dnBuilder, X509Metadata metadata,
		String oid, String defaultValue) {
	
	String value = null;
	if (metadata.oids != null && metadata.oids.containsKey(oid)) {
		value = metadata.oids.get(oid);
	}
	if (StringUtils.isEmpty(value)) {
		value = defaultValue;
	}
	
	if (!StringUtils.isEmpty(value)) {
		try {
			Field field = BCStyle.class.getField(oid);
			ASN1ObjectIdentifier objectId = (ASN1ObjectIdentifier) field.get(null);
			dnBuilder.addRDN(objectId, value);
		} catch (Exception e) {
			logger.error(MessageFormat.format("Failed to set OID \"{0}\"!", oid) ,e);
		}
	}
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:22,代碼來源:X509Utils.java

示例13: generateTestCertificate

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
public static X509Certificate generateTestCertificate(KeyPair pair) throws CertificateException, OperatorCreationException {
    final X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
    final X500Name cn = nameBuilder.addRDN(BCStyle.CN, "Test Certificate").build();

    final byte[] encoded = pair.getPublic().getEncoded();
    final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(ASN1Sequence.getInstance(encoded));

    final X509v1CertificateBuilder certBuilder = new X509v1CertificateBuilder(
            cn,
            BigInteger.valueOf(System.currentTimeMillis()),
            new Date(System.currentTimeMillis() - 10000),
            new Date(System.currentTimeMillis() + 10000),
            cn,
            subjectPublicKeyInfo
    );

    final JcaContentSignerBuilder contentSignerBuilder = new JcaContentSignerBuilder("SHA256WithRSAEncryption");
    final ContentSigner contentSigner = contentSignerBuilder.build(pair.getPrivate());
    final X509CertificateHolder certificateHolder = certBuilder.build(contentSigner);

    return new JcaX509CertificateConverter().setProvider( "BC" ).getCertificate(certificateHolder);
}
 
開發者ID:gini,項目名稱:jersey-smime,代碼行數:23,代碼來源:KeyTools.java

示例14: createEntryValue

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private ASN1Encodable createEntryValue(ASN1ObjectIdentifier oid, String value)
{
    X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);

    builder.addRDN(oid, value);
    
    X500Name name = builder.build();

    ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive();
    ASN1Set set = ASN1Set.getInstance(seq.getObjectAt(0).toASN1Primitive());
    seq = (ASN1Sequence)set.getObjectAt(0);

    return seq.getObjectAt(1);
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:15,代碼來源:X500NameTest.java

示例15: createEntryValueFromString

import org.bouncycastle.asn1.x500.X500NameBuilder; //導入依賴的package包/類
private ASN1Encodable createEntryValueFromString(ASN1ObjectIdentifier oid, String value)
{
    X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);

    builder.addRDN(oid, value);

    X500Name name = new X500Name(builder.build().toString());

    ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive();
    ASN1Set set = ASN1Set.getInstance(seq.getObjectAt(0).toASN1Primitive());
    seq = (ASN1Sequence)set.getObjectAt(0);

    return seq.getObjectAt(1);
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:15,代碼來源:X500NameTest.java


注:本文中的org.bouncycastle.asn1.x500.X500NameBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。