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


Java X509CertificateHolder類代碼示例

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


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

示例1: generate

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的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: getSignersCertificates

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
private Collection<X509Certificate> getSignersCertificates(CMSSignedData previewSignerData) {
    Collection<X509Certificate> result = new HashSet<X509Certificate>();
    Store<?> certStore = previewSignerData.getCertificates();
    SignerInformationStore signers = previewSignerData.getSignerInfos();
    Iterator<?> it = signers.getSigners().iterator();
    while (it.hasNext()) {
        SignerInformation signer = (SignerInformation) it.next();
        @SuppressWarnings("unchecked")
        Collection<?> certCollection = certStore.getMatches(signer.getSID());
        Iterator<?> certIt = certCollection.iterator();
        X509CertificateHolder certificateHolder = (X509CertificateHolder) certIt.next();
        try {
            result.add(new JcaX509CertificateConverter().getCertificate(certificateHolder));
        } catch (CertificateException error) {
        }
    }
    return result;

}
 
開發者ID:demoiselle,項目名稱:signer,代碼行數:20,代碼來源:CAdESSigner.java

示例3: generateP7B

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
public CMSSignedData generateP7B(X509CertificateHolder caCertificate, PrivateKey caPrivateKey) {
    try {
        List<X509CertificateHolder> certChain = new ArrayList<X509CertificateHolder>();
        certChain.add(caCertificate);

        Store certs = new JcaCertStore(certChain);

        CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
        ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BouncyCastleProvider.PROVIDER_NAME).build(caPrivateKey);

        cmsSignedDataGenerator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
                new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build())
        .build(sha1Signer, caCertificate));
        cmsSignedDataGenerator.addCertificates(certs);

        CMSTypedData chainMessage = new CMSProcessableByteArray("chain".getBytes());
        CMSSignedData sigData = cmsSignedDataGenerator.generate(chainMessage, false);

        return sigData;
        
    } catch(Exception e) {
        throw new RuntimeException("Error while generating certificate chain: " + e.getMessage(), e);
    }
}
 
開發者ID:fabiusks,項目名稱:cert-services,代碼行數:25,代碼來源:P7BService.java

示例4: verifySignature

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
public static boolean verifySignature(CMSSignedData cmsSignedData, X509Certificate cert) {
    try {
        if (Security.getProvider("BC") == null)
            Security.addProvider(new BouncyCastleProvider());

        Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
        X509CertificateHolder ch = new X509CertificateHolder(cert.getEncoded());
        for (SignerInformation si : signers)
            if (si.getSID().match(ch))
                if (si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(ch)))
                    return true;
    } catch (Exception e) {}
    return false;
}
 
開發者ID:damianofalcioni,項目名稱:Websocket-Smart-Card-Signer,代碼行數:15,代碼來源:PKCS7Manager.java

示例5: createTrustStore

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
/**
 * "ca.pem" from Reader
 */
public static KeyStore createTrustStore(final Reader certReader) throws IOException, CertificateException,
        KeyStoreException, NoSuchAlgorithmException {
    try (PEMParser pemParser = new PEMParser(certReader)) {
        X509CertificateHolder certificateHolder = (X509CertificateHolder) pemParser.readObject();
        Certificate caCertificate = new JcaX509CertificateConverter()
                .setProvider("BC")
                .getCertificate(certificateHolder);

        KeyStore trustStore = KeyStore.getInstance("JKS");
        trustStore.load(null);
        trustStore.setCertificateEntry("ca", caCertificate);

        return trustStore;
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:19,代碼來源:VespaSSLConfig.java

示例6: fingerprint

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
public static String fingerprint(X509CertificateHolder c)
        throws IOException, CertificateEncodingException {

    byte[] der      = c.getEncoded();
    byte[] sha1     = sha256DigestOf(der);
    byte[] hexBytes = Hex.encode(sha1);
    String hex = new String(hexBytes,
                            "ASCII").toUpperCase();

    final StringBuilder fp = new StringBuilder();
    int                 i  = 0;
    fp.append(hex.substring(i,
                            i + 2));
    while ((i += 2) < hex.length()) {
        fp.append(':');
        fp.append(hex.substring(i,
                                i + 2));
    }
    return fp.toString();
}
 
開發者ID:Zubnix,項目名稱:rtcdcjava,代碼行數:21,代碼來源:RTCCertificate.java

示例7: createAndInitTrustManagerFactory

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
private TrustManagerFactory createAndInitTrustManagerFactory() throws Exception {
    X509Certificate caCertHolder;
    if (caCertFileName != null) {
        caCertHolder = readCertFile(caCert);
    } else {
        caCertHolder = certificateConverter.getCertificate((X509CertificateHolder) readPEMFile(caCert));
    }

    KeyStore caKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    caKeyStore.load(null, null);
    caKeyStore.setCertificateEntry("caCert-cert", caCertHolder);

    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(caKeyStore);
    return trustManagerFactory;
}
 
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:17,代碼來源:CertPemClientCredentials.java

示例8: convertHolders

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
private CollectionCertStoreParameters convertHolders(JcaX509CertificateConverter certificateConverter, JcaX509CRLConverter crlConverter)
    throws CertificateException, CRLException
{
    List jcaObjs = new ArrayList(certs.size() + crls.size());

    for (Iterator it = certs.iterator(); it.hasNext();)
    {
        jcaObjs.add(certificateConverter.getCertificate((X509CertificateHolder)it.next()));
    }

    for (Iterator it = crls.iterator(); it.hasNext();)
    {
        jcaObjs.add(crlConverter.getCRL((X509CRLHolder)it.next()));
    }

    return new CollectionCertStoreParameters(jcaObjs);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:18,代碼來源:JcaCertStoreBuilder.java

示例9: finaliseMessage

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
private ProtectedPKIMessage finaliseMessage(PKIHeader header, DERBitString protection)
{
    if (!extraCerts.isEmpty())
    {
        CMPCertificate[] cmpCerts = new CMPCertificate[extraCerts.size()];

        for (int i = 0; i != cmpCerts.length; i++)
        {
            cmpCerts[i] = new CMPCertificate(((X509CertificateHolder)extraCerts.get(i)).toASN1Structure());
        }

        return new ProtectedPKIMessage(new PKIMessage(header, body, protection, cmpCerts));
    }
    else
    {
        return new ProtectedPKIMessage(new PKIMessage(header, body, protection));
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:19,代碼來源:ProtectedPKIMessageBuilder.java

示例10: isVerified

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
public boolean isVerified(X509CertificateHolder certHolder, DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
    if (digAlg == null)
    {
        throw new CMPException("cannot find algorithm for digest from signature");
    }

    DigestCalculator digester;

    try
    {
        digester = digesterProvider.get(digAlg);
    }
    catch (OperatorCreationException e)
    {
        throw new CMPException("unable to create digester: " + e.getMessage(), e);
    }

    CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

    return Arrays.areEqual(certStatus.getCertHash().getOctets(), digester.getDigest());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:CertificateStatus.java

示例11: getCertificates

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
/**
 * Return the extra certificates associated with this message.
 *
 * @return an array of extra certificates, zero length if none present.
 */
public X509CertificateHolder[] getCertificates()
{
    CMPCertificate[] certs = pkiMessage.getExtraCerts();

    if (certs == null)
    {
        return new X509CertificateHolder[0];
    }

    X509CertificateHolder[] res = new X509CertificateHolder[certs.length];
    for (int i = 0; i != certs.length; i++)
    {
        res[i] = new X509CertificateHolder(certs[i].getX509v3PKCert());
    }

    return res;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:23,代碼來源:ProtectedPKIMessage.java

示例12: build

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
public ContentVerifierProvider build(final AsymmetricKeyParameter publicKey)
    throws OperatorCreationException
{
    return new ContentVerifierProvider()
    {
        public boolean hasAssociatedCertificate()
        {
            return false;
        }

        public X509CertificateHolder getAssociatedCertificate()
        {
            return null;
        }

        public ContentVerifier get(AlgorithmIdentifier algorithm)
            throws OperatorCreationException
        {
            BcSignerOutputStream stream = createSignatureStream(algorithm, publicKey);

            return new SigVerifier(algorithm, stream);
        }
    };
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:BcContentVerifierProviderBuilder.java

示例13: getCertificates

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
Store getCertificates(ASN1Set certSet)
{
    if (certSet != null)
    {
        List certList = new ArrayList(certSet.size());

        for (Enumeration en = certSet.getObjects(); en.hasMoreElements();)
        {
            ASN1Primitive obj = ((ASN1Encodable)en.nextElement()).toASN1Primitive();

            if (obj instanceof ASN1Sequence)
            {
                certList.add(new X509CertificateHolder(Certificate.getInstance(obj)));
            }
        }

        return new CollectionStore(certList);
    }

    return new CollectionStore(new ArrayList());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:CMSSignedHelper.java

示例14: verify

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
/**
 * Verify that the given verifier can successfully verify the signature on
 * this SignerInformation object.
 *
 * @param verifier a suitably configured SignerInformationVerifier.
 * @return true if the signer information is verified, false otherwise.
 * @throws org.bouncycastle.cms.CMSVerifierCertificateNotValidException if the provider has an associated certificate and the certificate is not valid at the time given as the SignerInfo's signing time.
 * @throws org.bouncycastle.cms.CMSException if the verifier is unable to create a ContentVerifiers or DigestCalculators.
 */
public boolean verify(SignerInformationVerifier verifier)
    throws CMSException
{
    Time signingTime = getSigningTime();   // has to be validated if present.

    if (verifier.hasAssociatedCertificate())
    {
        if (signingTime != null)
        {
            X509CertificateHolder dcv = verifier.getAssociatedCertificate();

            if (!dcv.isValidOn(signingTime.getDate()))
            {
                throw new CMSVerifierCertificateNotValidException("verifier not valid at signingTime");
            }
        }
    }

    return doVerify(verifier);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:30,代碼來源:SignerInformation.java

示例15: getCertificatesFromStore

import org.bouncycastle.cert.X509CertificateHolder; //導入依賴的package包/類
static List getCertificatesFromStore(Store certStore)
    throws CMSException
{
    List certs = new ArrayList();

    try
    {
        for (Iterator it = certStore.getMatches(null).iterator(); it.hasNext();)
        {
            X509CertificateHolder c = (X509CertificateHolder)it.next();

            certs.add(c.toASN1Structure());
        }

        return certs;
    }
    catch (ClassCastException e)
    {
        throw new CMSException("error processing certs", e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:CMSUtils.java


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