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


Java SMIMESignedGenerator.addSigner方法代码示例

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


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

示例1: generateMultiPartGost

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartGost(
    MimeBodyPart msg)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_signGostCert);

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signGostKP.getPrivate(), _signGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
    gen.addCertificatesAndCRLs(certs);

    return gen.generate(msg, "BC");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:20,代码来源:SMIMESignedTest.java

示例2: generateMultiPartECGost

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartECGost(
    MimeBodyPart msg)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_signEcGostCert);

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signEcGostKP.getPrivate(), _signEcGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
    gen.addCertificatesAndCRLs(certs);

    return gen.generate(msg, "BC");
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:20,代码来源:SMIMESignedTest.java

示例3: generateEncapsulatedRsa

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeBodyPart generateEncapsulatedRsa(String digestOid, MimeBodyPart msg) 
    throws Exception
{
    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, digestOid, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    return gen.generateEncapsulated(msg, "BC");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:21,代码来源:SMIMESignedTest.java

示例4: signMessage

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private static MimeMultipart signMessage(MimeBodyPart mbp)
        throws Exception
{
     // Open the key store
	char[] pwd = "password".toCharArray();
	
    KeyStore ks = MailsterKeyStoreFactory.loadKeyStore("PKCS12", "clients.p12", pwd);
    String alias = MailsterKeyStoreFactory.DEFAULT_CERT_ALIAS;
    Certificate[] chain = ks.getCertificateChain(alias);
    PrivateKey privateKey = (PrivateKey) ks.getKey(alias, pwd);

    ArrayList<Certificate> certList = new ArrayList<Certificate>();

    for (int i = 0; i < chain.length; i++)
        certList.add(chain[i]);

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

    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    caps.addCapability(SMIMECapability.dES_CBC);
    caps.addCapability(SMIMECapability.aES256_CBC);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(privateKey, (X509Certificate) chain[0],
            SMIMESignedGenerator.DIGEST_SHA1, 
            new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certs);

    return gen.generate(mbp, "BC");
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:40,代码来源:SendMultipleMail.java

示例5: signMessage

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private static MimeMultipart signMessage(MimeBodyPart mbp)
        throws Exception
{
    // Open the key store
	char[] pwd = "password".toCharArray();
	
    KeyStore ks = MailsterKeyStoreFactory.loadKeyStore("PKCS12", "clients.p12", pwd);
    String alias = MailsterKeyStoreFactory.DEFAULT_CERT_ALIAS;
    Certificate[] chain = ks.getCertificateChain(alias);
    PrivateKey privateKey = (PrivateKey) ks.getKey(alias, pwd);

    ArrayList<Certificate> certList = new ArrayList<Certificate>();

    for (int i = 0; i < chain.length; i++)
        certList.add(chain[i]);

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

    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    caps.addCapability(SMIMECapability.dES_CBC);
    caps.addCapability(SMIMECapability.aES256_CBC);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(privateKey, (X509Certificate) chain[0],
            SMIMESignedGenerator.DIGEST_SHA1, 
            new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certs);

    return gen.generate(mbp, "BC");
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:40,代码来源:EncryptedMailTest.java

示例6: generateMultiPartRsaPSS

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
    String digestOid,
    MimeBodyPart msg,
    Date         signingTime)
    throws Exception
{
    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    if (signingTime != null)
    {
        signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
    }

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.ENCRYPTION_RSA_PSS, digestOid, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    return gen.generate(msg, "BC");
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:29,代码来源:SMIMESignedTest.java

示例7: testMimeMultipartBinaryReader

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryReader()
    throws Exception
{
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    MimeMultipart mm = gen.generate(m, "BC");

    SMIMESigned s = new SMIMESigned(mm, "binary");

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:27,代码来源:SMIMESignedTest.java

示例8: testHeadersEncapsulated

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testHeadersEncapsulated()
    throws Exception
{
    List           certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certs);

    MimeBodyPart res = gen.generateEncapsulated(msg, "BC");

    assertEquals("application/pkcs7-mime; name=smime.p7m; smime-type=signed-data", res.getHeader("Content-Type")[0]);
    assertEquals("attachment; filename=\"smime.p7m\"", res.getHeader("Content-Disposition")[0]);
    assertEquals("S/MIME Cryptographic Signed Data", res.getHeader("Content-Description")[0]);
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:26,代码来源:SMIMESignedTest.java

示例9: testMimeMultipartBinaryParser

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryParser()
    throws Exception
{
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    MimeMultipart mm = gen.generate(m, "BC");

    SMIMESignedParser s = new SMIMESignedParser(mm, "binary");

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:27,代码来源:SMIMESignedTest.java

示例10: testMD5WithRSAAddSignersSHA1

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMD5WithRSAAddSignersSHA1()
    throws Exception
{
    MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg, SMIMESignedGenerator.RFC3851_MICALGS);
    SMIMESigned   s = new SMIMESigned(smm);

    List certList = new ArrayList();

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

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_MD5);
    
    gen.addSigners(s.getSignerInfos());

    gen.addCertificatesAndCRLs(certs);

    smm = gen.generate(msg, "BC");

    SMIMESigned newS =  new SMIMESigned(gen.generate(msg, "BC"));

    verifyMessageBytes(msg, newS.getContent());

    verifySigners(newS.getCertificatesAndCRLs("Collection", "BC"), newS.getSignerInfos());

    assertEquals("\"md5,sha-1\"", getMicAlg(smm));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:33,代码来源:SMIMESignedTest.java

示例11: testSHA1withDSA

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testSHA1withDSA()
    throws Exception
{
    dsaSignKP   = CMSTestUtil.makeDsaKeyPair();
    dsaSignCert = CMSTestUtil.makeCertificate(dsaSignKP, _origDN, dsaSignKP, _origDN);

    dsaOrigKP   = CMSTestUtil.makeDsaKeyPair();
    dsaOrigCert = CMSTestUtil.makeCertificate(dsaOrigKP, _signDN, dsaSignKP, _origDN);

    List           certList = new ArrayList();

    certList.add(dsaOrigCert);
    certList.add(dsaSignCert);

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(dsaOrigKP.getPrivate(), dsaOrigCert, SMIMESignedGenerator.DIGEST_SHA1);
    gen.addCertificatesAndCRLs(certs);


    MimeMultipart smm = gen.generate(msg, "BC");
    SMIMESigned   s = new  SMIMESigned(smm);

    verifyMessageBytes(msg, s.getContent());

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:31,代码来源:SMIMESignedTest.java

示例12: testMimeMultipart

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipart()
    throws Exception
{
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    MimeMultipart mm = gen.generate(m, "BC");

    SMIMESigned s = new SMIMESigned(mm);

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());

    byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(SMIMESignedGenerator.DIGEST_SHA1);

    AttributeTable table = ((SignerInformation)s.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
    Attribute hash = table.get(CMSAttributes.messageDigest);

    assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:34,代码来源:SMIMESignedTest.java

示例13: testSignAttachmentOnly

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testSignAttachmentOnly()
    throws Exception
{
    MimeMessage m = loadMessage("attachonly.eml");

    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    MimeMultipart mm = gen.generate(m, "BC");

    SMIMESigned s = new SMIMESigned(mm);

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());

    SMIMESignedParser sp = new SMIMESignedParser(mm);

    verifySigners(sp.getCertificatesAndCRLs("Collection", "BC"), sp.getSignerInfos());
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:31,代码来源:SMIMESignedTest.java

示例14: testMimeMultipartBinaryParserGetMimeContent

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryParserGetMimeContent()
    throws Exception
{
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

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

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

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    MimeMultipart mm = gen.generate(m, "BC");

    SMIMESignedParser s = new SMIMESignedParser(mm, "binary");

    verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());

    MimeMessage bp = s.getContentAsMimeMessage(Session.getDefaultInstance(new Properties()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:SMIMESignedTest.java

示例15: testCompressedSHA1WithRSA

import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testCompressedSHA1WithRSA()
    throws Exception
{
    List           certList = new ArrayList();

    certList.add(origCert);
    certList.add(signCert);

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

    ASN1EncodableVector         signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector       caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    caps.addCapability(SMIMECapability.dES_CBC);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(origKP.getPrivate(), origCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certs);

    MimeMultipart smp = gen.generate(msg, "BC");

    MimeMessage bp2 = new MimeMessage((Session)null);                          

    bp2.setContent(smp);

    bp2.saveChanges();

    SMIMECompressedGenerator    cgen = new SMIMECompressedGenerator();

    MimeBodyPart cbp = cgen.generate(bp2, SMIMECompressedGenerator.ZLIB);

    SMIMECompressed cm = new SMIMECompressed(cbp);

    MimeMultipart mm = (MimeMultipart)SMIMEUtil.toMimeBodyPart(cm.getContent()).getContent();
    
    SMIMESigned s = new SMIMESigned(mm);

    ByteArrayOutputStream _baos = new ByteArrayOutputStream();
    msg.writeTo(_baos);
    _baos.close();
    byte[] _msgBytes = _baos.toByteArray();
    _baos = new ByteArrayOutputStream();
    s.getContent().writeTo(_baos);
    _baos.close();
    byte[] _resBytes = _baos.toByteArray();
    
    assertEquals(true, Arrays.areEqual(_msgBytes, _resBytes));

    certs = s.getCertificatesAndCRLs("Collection", "BC");

    SignerInformationStore  signers = s.getSignerInfos();
    Collection              c = signers.getSigners();
    Iterator                it = c.iterator();

    while (it.hasNext())
    {
        SignerInformation   signer = (SignerInformation)it.next();
        Collection          certCollection = certs.getCertificates(selectorConverter.getCertSelector(signer.getSID()));

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

        assertEquals(true, signer.verify(cert, "BC"));
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:73,代码来源:SMIMECompressedTest.java


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