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


Java Extension類代碼示例

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


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

示例1: generate

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public X509Certificate generate(String dn, KeyPair keyPair) throws CertificateException {
    try {
        Security.addProvider(new BouncyCastleProvider());
        AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
        AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
        AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(keyPair.getPrivate().getEncoded());
        SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
        ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(privateKeyAsymKeyParam);
        X500Name name = new X500Name(dn);
        Date from = new Date();
        Date to = new Date(from.getTime() + days * 86400000L);
        BigInteger sn = new BigInteger(64, new SecureRandom());
        X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);

        if (subjectAltName != null)
            v3CertGen.addExtension(Extension.subjectAlternativeName, false, subjectAltName);
        X509CertificateHolder certificateHolder = v3CertGen.build(sigGen);
        return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
    } catch (CertificateException ce) {
        throw ce;
    } catch (Exception e) {
        throw new CertificateException(e);
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:TestSslUtils.java

示例2: generateOCSPRequest

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
/**
 * Generates an OCSP request using BouncyCastle.
 * @param issuerCert	certificate of the issues
 * @param serialNumber	serial number
 * @return	an OCSP request
 * @throws OCSPException
 * @throws IOException
 */
private static OCSPReq generateOCSPRequest(X509Certificate issuerCert, BigInteger serialNumber) throws OCSPException, IOException, OperatorException, CertificateEncodingException {
    //Add provider BC
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    
    JcaDigestCalculatorProviderBuilder digestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder();
    DigestCalculatorProvider digestCalculatorProvider = digestCalculatorProviderBuilder.build();
    DigestCalculator digestCalculator = digestCalculatorProvider.get(CertificateID.HASH_SHA1);
    // Generate the id for the certificate we are looking for
    CertificateID id = new CertificateID(digestCalculator, new JcaX509CertificateHolder(issuerCert), serialNumber);
    
    // basic request generation with nonce
    OCSPReqBuilder gen = new OCSPReqBuilder();
    
    gen.addRequest(id);
    
    // create details for nonce extension
    Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, new DEROctetString(new DEROctetString(PdfEncryption.createDocumentId()).getEncoded()));
    gen.setRequestExtensions(new Extensions(new Extension[]{ext}));
    
    return gen.build();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:30,代碼來源:OcspClientBouncyCastle.java

示例3: extractX509CSRDnsNames

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public static List<String> extractX509CSRDnsNames(PKCS10CertificationRequest certReq) {
    
    List<String> dnsNames = new ArrayList<>();
    Attribute[] attributes = certReq.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
    for (Attribute attribute : attributes) {
        for (ASN1Encodable value : attribute.getAttributeValues()) {
            Extensions extensions = Extensions.getInstance(value);
            GeneralNames gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
            for (GeneralName name : gns.getNames()) {
                if (name.getTagNo() == GeneralName.dNSName) {
                    dnsNames.add(((DERIA5String) name.getName()).getString());
                }
            }
        }
    }
    return dnsNames;
}
 
開發者ID:yahoo,項目名稱:athenz,代碼行數:18,代碼來源:Crypto.java

示例4: getExtensionValue

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public byte[] getExtensionValue(String oid) 
{
    Extensions extensions = cert.getAcinfo().getExtensions();

    if (extensions != null)
    {
        Extension ext = extensions.getExtension(new ASN1ObjectIdentifier(oid));

        if (ext != null)
        {
            try
            {
                return ext.getExtnValue().getEncoded(ASN1Encoding.DER);
            }
            catch (Exception e)
            {
                throw new RuntimeException("error encoding " + e.toString());
            }
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:X509V2AttributeCertificate.java

示例5: getExtensionOIDs

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
private Set getExtensionOIDs(
    boolean critical) 
{
    Extensions  extensions = cert.getAcinfo().getExtensions();

    if (extensions != null)
    {
        Set             set = new HashSet();
        Enumeration     e = extensions.oids();

        while (e.hasMoreElements())
        {
            ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement();
            Extension            ext = extensions.getExtension(oid);

            if (ext.isCritical() == critical)
            {
                set.add(oid.getId());
            }
        }

        return set;
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:27,代碼來源:X509V2AttributeCertificate.java

示例6: copyAndAddExtension

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
/**
 * Add a given extension field for the standard extensions tag (tag 3)
 * copying the extension value from another certificate.
 *
 * @param oid the OID defining the extension type.
 * @param isCritical true if the copied extension is to be marked as critical, false otherwise.
 * @param certHolder the holder for the certificate that the extension is to be copied from.
 * @return this builder object.
 */
public X509v3CertificateBuilder copyAndAddExtension(
    ASN1ObjectIdentifier oid,
    boolean isCritical,
    X509CertificateHolder certHolder)
{
    Certificate cert = certHolder.toASN1Structure();

    Extension extension = cert.getTBSCertificate().getExtensions().getExtension(oid);

    if (extension == null)
    {
        throw new NullPointerException("extension " + oid + " not present");
    }

    extGenerator.addExtension(oid, isCritical, extension.getExtnValue().getOctets());

    return this;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:28,代碼來源:X509v3CertificateBuilder.java

示例7: getRevokedCertificate

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public X509CRLEntryHolder getRevokedCertificate(BigInteger serialNumber)
{
    GeneralNames currentCA = issuerName;
    for (Enumeration en = x509CRL.getRevokedCertificateEnumeration(); en.hasMoreElements();)
    {
        TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)en.nextElement();

        if (entry.getUserCertificate().getValue().equals(serialNumber))
        {
            return new X509CRLEntryHolder(entry, isIndirect, currentCA);
        }

        if (isIndirect && entry.hasExtensions())
        {
            Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);

            if (currentCaName != null)
            {
                currentCA = GeneralNames.getInstance(currentCaName.getParsedValue());
            }
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:X509CRLHolder.java

示例8: getExtensionValue

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public byte[] getExtensionValue(String oid) 
{
    Extensions exts = c.getTBSCertificate().getExtensions();

    if (exts != null)
    {
        Extension   ext = exts.getExtension(new ASN1ObjectIdentifier(oid));

        if (ext != null)
        {
            try
            {
                return ext.getExtnValue().getEncoded();
            }
            catch (Exception e)
            {
                throw new IllegalStateException("error parsing " + e.toString());
            }
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:X509CertificateObject.java

示例9: getExtensionValue

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public byte[] getExtensionValue(String oid)
{
    Extensions exts = c.getTBSCertList().getExtensions();

    if (exts != null)
    {
        Extension ext = exts.getExtension(new ASN1ObjectIdentifier(oid));

        if (ext != null)
        {
            try
            {
                return ext.getExtnValue().getEncoded();
            }
            catch (Exception e)
            {
                throw new IllegalStateException("error parsing " + e.toString());
            }
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:X509CRLObject.java

示例10: loadCRLEntries

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
private Set loadCRLEntries()
{
    Set entrySet = new HashSet();
    Enumeration certs = c.getRevokedCertificateEnumeration();

    X500Name previousCertificateIssuer = null; // the issuer
    while (certs.hasMoreElements())
    {
        TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement();
        X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
        entrySet.add(crlEntry);
        if (isIndirect && entry.hasExtensions())
        {
            Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);

            if (currentCaName != null)
            {
                previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
            }
        }
    }

    return entrySet;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:X509CRLObject.java

示例11: getExtensionOIDs

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
private Set getExtensionOIDs(boolean critical)
{
    Extensions extensions = c.getExtensions();

    if (extensions != null)
    {
        Set set = new HashSet();
        Enumeration e = extensions.oids();

        while (e.hasMoreElements())
        {
            ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
            Extension ext = extensions.getExtension(oid);

            if (critical == ext.isCritical())
            {
                set.add(oid.getId());
            }
        }

        return set;
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:X509CRLEntryObject.java

示例12: getExtensionValue

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public byte[] getExtensionValue(String oid)
{
    Extension ext = getExtension(new ASN1ObjectIdentifier(oid));

    if (ext != null)
    {
        try
        {
            return ext.getExtnValue().getEncoded();
        }
        catch (Exception e)
        {
            throw new RuntimeException("error encoding " + e.toString());
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:19,代碼來源:X509CRLEntryObject.java

示例13: getInstance

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public static CertEtcToken getInstance(Object obj)
{
    if (obj instanceof CertEtcToken)
    {
        return (CertEtcToken)obj;
    }
    else if (obj instanceof ASN1TaggedObject)
    {
        return new CertEtcToken((ASN1TaggedObject)obj);
    }
    else if (obj != null)
    {
        return new CertEtcToken(Extension.getInstance(obj));
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:18,代碼來源:CertEtcToken.java

示例14: getExtensionValue

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
public byte[] getExtensionValue(String oid)
{
    Extensions exts = req.getExtensions();

    if (exts != null)
    {
        Extension   ext = exts.getExtension(new ASN1ObjectIdentifier(oid));

        if (ext != null)
        {
            try
            {
                return ext.getExtnValue().getEncoded();
            }
            catch (Exception e)
            {
                throw new RuntimeException("error encoding " + e.toString());
            }
        }
    }

    return null;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:TimeStampRequest.java

示例15: setCertificateExtensions

import org.bouncycastle.asn1.x509.Extension; //導入依賴的package包/類
static void setCertificateExtensions(X509Certificate certificate) throws IOException, ParseException {
    String cpsUri = CertificateHelper.getCertificatePoliciesExtension(certificate);
    if (!cpsUri.isEmpty()) {
        access.setCritical(CERTIFICATE_POLICIES_ID, CertificateHelper.isExtensionCritical(Extension.certificatePolicies,
                certificate.getCriticalExtensionOIDs()));
        access.setAnyPolicy(true);
        access.setCpsUri(cpsUri);
    }
    String skipCerts = CertificateHelper.getInhabitAnyPolicyExtension(certificate);
    if (!skipCerts.isEmpty()) {
        access.setCritical(INHABIT_ANY_POLICY_ID, CertificateHelper.isExtensionCritical(Extension.inhibitAnyPolicy,
                certificate.getCriticalExtensionOIDs()));
        access.setInhibitAnyPolicy(true);
        access.setSkipCerts(skipCerts);
    }
    String[] subjectDirectoryData = CertificateHelper.getSubjectDirectoryExtension(certificate);
    if (subjectDirectoryData != null) {
        access.setCritical(SUBJECT_DIRECTORY_ATTRIBUTES_ID, CertificateHelper.isExtensionCritical(Extension.subjectDirectoryAttributes,
                certificate.getCriticalExtensionOIDs()));
        access.setDateOfBirth(subjectDirectoryData[0]);
        access.setSubjectDirectoryAttribute(COUNTRY_OF_CITIZENSHIP_ID, subjectDirectoryData[1]);
        access.setSubjectDirectoryAttribute(PLACE_OF_BIRTH_ID, subjectDirectoryData[2]);
        access.setGender(subjectDirectoryData[3]);
    }
}
 
開發者ID:stevanmilic,項目名稱:X509-certificate-manager,代碼行數:26,代碼來源:GuiHelper.java


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