当前位置: 首页>>代码示例>>Java>>正文


Java CMSSignedDataGenerator.addCertificatesAndCRLs方法代码示例

本文整理汇总了Java中org.bouncycastle.cms.CMSSignedDataGenerator.addCertificatesAndCRLs方法的典型用法代码示例。如果您正苦于以下问题:Java CMSSignedDataGenerator.addCertificatesAndCRLs方法的具体用法?Java CMSSignedDataGenerator.addCertificatesAndCRLs怎么用?Java CMSSignedDataGenerator.addCertificatesAndCRLs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.cms.CMSSignedDataGenerator的用法示例。


在下文中一共展示了CMSSignedDataGenerator.addCertificatesAndCRLs方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assinar

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public byte[] assinar(KeyStore keystore, String alias, char[] password, byte[] request) {
    try {
        PrivateKey key = (PrivateKey) keystore.getKey(alias, password);
        X509Certificate cert = (X509Certificate) keystore.getCertificate(alias);
        List<X509Certificate> certs = new ArrayList<X509Certificate>();
        certs.add(cert);
        CertStore certsAndCrls = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certs));

        // setup the generator
        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
        generator.addSigner(key, cert, CMSSignedDataGenerator.DIGEST_SHA256);
        generator.addCertificatesAndCRLs(certsAndCrls);

        // Create the signed data object
        CMSProcessable data = new CMSProcessableByteArray(request);
        CMSSignedData signed = generator.generate(data, true, keystore.getProvider());

        return signed.getEncoded();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:humbertopacheco,项目名称:timestamp,代码行数:25,代码来源:RequestSigner.java

示例2: testSHA1WithRSANoAttributes

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testSHA1WithRSANoAttributes()
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray("Hello world!".getBytes());

    certList.add(_origCert);
    certList.add(_signCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);

    //
    // compute expected content digest
    //
    MessageDigest md = MessageDigest.getInstance("SHA1", BC);
    
    verifySignatures(s, md.digest("Hello world!".getBytes()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:28,代码来源:SignedDataTest.java

示例3: rsaPSSTest

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private void rsaPSSTest(String digestName, String digestOID)
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray("Hello world!".getBytes());

    certList.add(_origCert);
    certList.add(_signCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.ENCRYPTION_RSA_PSS, digestOID);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);

    //
    // compute expected content digest
    //
    MessageDigest md = MessageDigest.getInstance(digestName, BC);

    verifySignatures(s, md.digest("Hello world!".getBytes()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:28,代码来源:SignedDataTest.java

示例4: testCertStoreReplacement

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testCertStoreReplacement()
    throws Exception
{
    List                  certList = new ArrayList();
    CMSProcessable        msg = new CMSProcessableByteArray("Hello World!".getBytes());


    certList.add(_signDsaCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData sd = gen.generate(msg, BC);

    //
    // create new certstore
    //
    certList = new ArrayList();
    certList.add(_origCert);
    certList.add(_signCert);

    certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    //
    // replace certs
    //
    sd = CMSSignedData.replaceCertificatesAndCRLs(sd, certs);

    verifySignatures(sd);
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:38,代码来源:SignedDataTest.java

示例5: testSHA1WithRSANoAttributes

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testSHA1WithRSANoAttributes()
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray(TEST_MESSAGE.getBytes());

    certList.add(_origCert);
    certList.add(_signCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);

    CMSSignedDataParser     sp = new CMSSignedDataParser(
            new CMSTypedStream(new ByteArrayInputStream(TEST_MESSAGE.getBytes())), s.getEncoded());
    
    sp.getSignedContent().drain();
    
    //
    // compute expected content digest
    //
    MessageDigest md = MessageDigest.getInstance("SHA1", BC);
    
    verifySignatures(sp, md.digest(TEST_MESSAGE.getBytes()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:33,代码来源:SignedDataStreamTest.java

示例6: testEncapsulatedCertStoreReplacement

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testEncapsulatedCertStoreReplacement()
    throws Exception
{
    List                  certList = new ArrayList();
    CMSProcessable        msg = new CMSProcessableByteArray("Hello World!".getBytes());


    certList.add(_signDsaCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData sd = gen.generate(msg, true, BC);

    //
    // create new certstore
    //
    certList = new ArrayList();
    certList.add(_origCert);
    certList.add(_signCert);

    certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    //
    // replace certs
    //
    sd = CMSSignedData.replaceCertificatesAndCRLs(sd, certs);

    verifySignatures(sd);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:38,代码来源:SignedDataTest.java

示例7: testCertOrdering2

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testCertOrdering2()
    throws Exception
{
    List                  certList = new ArrayList();
    CMSProcessable        msg = new CMSProcessableByteArray("Hello World!".getBytes());

    certList.add(_signCert);
    certList.add(_signDsaCert);
    certList.add(_origCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData sd = gen.generate(msg, true, BC);

    certs = sd.getCertificatesAndCRLs("Collection", BC);
    Iterator it = certs.getCertificates(null).iterator();

    assertEquals(_signCert, it.next());
    assertEquals(_signDsaCert, it.next());
    assertEquals(_origCert, it.next());
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:29,代码来源:SignedDataTest.java

示例8: testDSANoAttributes

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testDSANoAttributes()
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray(TEST_MESSAGE.getBytes());

    certList.add(_origDsaCert);
    certList.add(_signCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origDsaKP.getPrivate(), _origDsaCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);

    CMSSignedDataParser     sp = new CMSSignedDataParser(
            new CMSTypedStream(new ByteArrayInputStream(TEST_MESSAGE.getBytes())), s.getEncoded());
    
    sp.getSignedContent().drain();
    
    //
    // compute expected content digest
    //
    MessageDigest md = MessageDigest.getInstance("SHA1", BC);
    
    verifySignatures(sp, md.digest(TEST_MESSAGE.getBytes()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:33,代码来源:SignedDataStreamTest.java

示例9: testSHA1WithRSAViaConfig

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testSHA1WithRSAViaConfig()
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray("Hello world!".getBytes());

    certList.add(_origCert);
    certList.add(_signCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    // set some bogus mappings.
    CMSConfig.setSigningEncryptionAlgorithmMapping(PKCSObjectIdentifiers.rsaEncryption.getId(), "XXXX");
    CMSConfig.setSigningDigestAlgorithmMapping(OIWObjectIdentifiers.idSHA1.getId(), "YYYY");

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    CMSSignedData s;

    try
    {
        // try the bogus mappings
        s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);
    }
    catch (NoSuchAlgorithmException e)
    {
        if (!e.getMessage().startsWith("Unknown signature type requested: YYYYWITHXXXX"))
        {
            throw e;
        }
    }
    finally
    {
        // reset to the real ones
        CMSConfig.setSigningEncryptionAlgorithmMapping(PKCSObjectIdentifiers.rsaEncryption.getId(), "RSA");
        CMSConfig.setSigningDigestAlgorithmMapping(OIWObjectIdentifiers.idSHA1.getId(), "SHA1"); 
    }

    s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);

    //
    // compute expected content digest
    //
    MessageDigest md = MessageDigest.getInstance("SHA1", BC);

    verifySignatures(s, md.digest("Hello world!".getBytes()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:53,代码来源:SignedDataTest.java

示例10: testSHA1WithRSACounterSignature

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testSHA1WithRSACounterSignature()
    throws Exception
{
    List                certList = new ArrayList();
    CMSProcessable      msg = new CMSProcessableByteArray("Hello World!".getBytes());

    certList.add(_signCert);
    certList.add(_origCert);

    certList.add(_signCrl);

    CertStore           certsAndCrls = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certsAndCrls);

    CMSSignedData s = gen.generate(msg, true, BC);
    SignerInformation origSigner = (SignerInformation)s.getSignerInfos().getSigners().toArray()[0];
    SignerInformationStore counterSigners1 = gen.generateCounterSigners(origSigner, BC);
    SignerInformationStore counterSigners2 = gen.generateCounterSigners(origSigner, BC);

    SignerInformation signer1 = SignerInformation.addCounterSigners(origSigner, counterSigners1);
    SignerInformation signer2 = SignerInformation.addCounterSigners(signer1, counterSigners2);

    SignerInformationStore cs = signer2.getCounterSignatures();
    Collection csSigners = cs.getSigners();
    assertEquals(2, csSigners.size());

    Iterator it = csSigners.iterator();
    while (it.hasNext())
    {
        SignerInformation   cSigner = (SignerInformation)it.next();
        Collection          certCollection = certsAndCrls.getCertificates(selectorConverter.getCertSelector(cSigner.getSID()));

        Iterator        certIt = certCollection.iterator();
        X509Certificate cert = (X509Certificate)certIt.next();

        assertNull(cSigner.getSignedAttributes().get(PKCSObjectIdentifiers.pkcs_9_at_contentType));
        assertEquals(true, cSigner.verify(cert, BC));
    }
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:46,代码来源:SignedDataTest.java

示例11: testWithAttributeCertificate

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public void testWithAttributeCertificate()
    throws Exception
{
    List                  certList = new ArrayList();
    CMSProcessable        msg = new CMSProcessableByteArray("Hello World!".getBytes());


    certList.add(_signDsaCert);

    CertStore           certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);

    gen.addCertificatesAndCRLs(certs);

    X509AttributeCertificate attrCert = CMSTestUtil.getAttributeCertificate();

    X509Store store = X509Store.getInstance("AttributeCertificate/Collection",
                                new X509CollectionStoreParameters(Collections.singleton(attrCert)), BC);

    gen.addAttributeCertificates(store);

    CMSSignedData sd = gen.generate(msg, BC);

    assertEquals(4, sd.getVersion());

    store = sd.getAttributeCertificates("Collection", BC);

    Collection coll = store.getMatches(null);

    assertEquals(1, coll.size());

    assertTrue(coll.contains(attrCert));
    
    //
    // create new certstore
    //
    certList = new ArrayList();
    certList.add(_origCert);
    certList.add(_signCert);

    certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), BC);


    //
    // replace certs
    //
    sd = CMSSignedData.replaceCertificatesAndCRLs(sd, certs);

    verifySignatures(sd);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:56,代码来源:SignedDataTest.java


注:本文中的org.bouncycastle.cms.CMSSignedDataGenerator.addCertificatesAndCRLs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。