• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JcaSimpleSignerInfoGeneratorBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder的典型用法代码示例。如果您正苦于以下问题:Java JcaSimpleSignerInfoGeneratorBuilder类的具体用法?Java JcaSimpleSignerInfoGeneratorBuilder怎么用?Java JcaSimpleSignerInfoGeneratorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JcaSimpleSignerInfoGeneratorBuilder类属于org.bouncycastle.cms.jcajce包,在下文中一共展示了JcaSimpleSignerInfoGeneratorBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createTimeStampToken

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public static TimeStampToken createTimeStampToken(PrivateKey privateKey, List<X509Certificate> certificateChain)
		throws Exception {

	Store certs = new JcaCertStore(certificateChain);

	TimeStampRequestGenerator requestGen = new TimeStampRequestGenerator();
	requestGen.setCertReq(true);
	TimeStampRequest request = requestGen.generate(TSPAlgorithms.SHA1, new byte[20], BigInteger.valueOf(100));

	TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
			new JcaSimpleSignerInfoGeneratorBuilder().build("SHA1withRSA", privateKey, certificateChain.get(0)),
			new JcaDigestCalculatorProviderBuilder().build()
					.get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1)),
			new ASN1ObjectIdentifier("1.2"));

	tsTokenGen.addCertificates(certs);
	return tsTokenGen.generate(request, BigInteger.ONE, new Date());
}
 
开发者ID:e-Contract,项目名称:jtrust,代码行数:19,代码来源:PKITestUtils.java


示例2: writeFragment

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void writeFragment(byte[] fragment)
    throws Exception
{
    if (cmsOut == null)
    {
        KeyStore nodeCAStore = nodeContext.getNodeCAStore();

        Certificate[] nodeCerts = nodeCAStore.getCertificateChain("nodeCA");

        cmsGen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA256withECDSA", (PrivateKey)nodeCAStore.getKey("nodeCA", new char[0]), (X509Certificate)nodeCerts[0]));

        for (Certificate cert : nodeCerts)
        {
            cmsGen.addCertificate(new JcaX509CertificateHolder((X509Certificate)cert));
        }

        cmsOut = cmsGen.open(bOut, true);
    }

    cmsOut.write(fragment);
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:22,代码来源:BoardHostingService.java


示例3: generateMultiPartGost

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeMultipart generateMultiPartGost(
    MimeBodyPart msg)
    throws Exception
{
    List certList = new ArrayList();

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

    Store certs = new JcaCertStore(certList);

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).build("GOST3411withGOST3410", _signGostKP.getPrivate(), _signGostCert));
    gen.addCertificates(certs);

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


示例4: generateMultiPartECGost

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeMultipart generateMultiPartECGost(
    MimeBodyPart msg)
    throws Exception
{
    List certList = new ArrayList();

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

    Store certs = new JcaCertStore(certList);

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).build("GOST3411withECGOST3410", _signEcGostKP.getPrivate(), _signEcGostCert));
    gen.addCertificates(certs);

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


示例5: writeTo

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Override
public void writeTo(SignedOutput out, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException {
    try {
        SMIMESignedGenerator gen = new SMIMESignedGenerator();
        SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", out.getPrivateKey(), out.getCertificate());
        gen.addSignerInfoGenerator(signer);

        MimeMultipart mp = gen.generate(EnvelopedWriter.createBodyPart(providers, out));
        String contentType = mp.getContentType();
        contentType = contentType.replace("\r\n", "").replace("\t", " ");
        headers.putSingle("Content-Type", contentType);
        mp.writeTo(os);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:17,代码来源:SignedWriter.java


示例6: testOutput2

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Test
public void testOutput2() throws Exception {
    SMIMESignedGenerator gen = new SMIMESignedGenerator();
    SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", privateKey, cert);
    gen.addSignerInfoGenerator(signer);

    MimeMultipart mp = gen.generate(createMsg());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mp.writeTo(os);

    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
    String contentType = mp.getContentType();
    contentType = contentType.replace("\r\n", "").replace("\t", " ");

    ByteArrayDataSource ds = new ByteArrayDataSource(is, contentType);
    MimeMultipart mm = new MimeMultipart(ds);
    MimeBodyPart part = (MimeBodyPart) mm.getBodyPart(0);


}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:22,代码来源:SignedTest.java


示例7: testPythonVerified

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Test
public void testPythonVerified() throws Exception {
    SMIMESignedGenerator gen = new SMIMESignedGenerator();
    SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", privateKey, cert);
    gen.addSignerInfoGenerator(signer);

    MimeMultipart mp = gen.generate(createMsg());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mp.writeTo(os);
    String contentType = mp.getContentType();
    contentType = contentType.replace("\r\n", "").replace("\t", " ");
    System.out.println(contentType);
    String s = new String(os.toByteArray());
    StringBuilder builder = new StringBuilder();
    builder.append("Content-Type: ").append(contentType).append("\r\n\r\n").append(s);
    String output = builder.toString();

    FileOutputStream fp = new FileOutputStream("smime_signed.txt");
    fp.write(output.getBytes());
    fp.close();


}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:24,代码来源:SignedTest.java


示例8: testPythonVerifiedBad

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Test
public void testPythonVerifiedBad() throws Exception {
    SMIMESignedGenerator gen = new SMIMESignedGenerator();
    SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", badKey, cert);
    gen.addSignerInfoGenerator(signer);

    MimeMultipart mp = gen.generate(createMsg());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mp.writeTo(os);
    String contentType = mp.getContentType();
    contentType = contentType.replace("\r\n", "").replace("\t", " ");
    System.out.println(contentType);
    String s = new String(os.toByteArray());
    StringBuilder builder = new StringBuilder();
    builder.append("Content-Type: ").append(contentType).append("\r\n\r\n").append(s);
    String output = builder.toString();

    FileOutputStream fp = new FileOutputStream("smime_signed_bad.txt");
    fp.write(output.getBytes());
    fp.close();


}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:24,代码来源:SignedTest.java


示例9: signRequest

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
/**
     * Signs a time stamp request
     *
     * @param privateKey private key to sign with
     * @param certificates certificate chain
     * @param request request to be signed
     * @return The signed request
     */
    public byte[] signRequest(PrivateKey privateKey, Certificate[] certificates, byte[] request, String algorithm) {
        try {
            logger.info(timeStampMessagesBundle.getString("info.timestamp.sign.request"));
            Security.addProvider(new BouncyCastleProvider());

            X509Certificate signCert = (X509Certificate) certificates[0];
            List<X509Certificate> certList = new ArrayList<>();
            certList.add(signCert);

            // setup the generator
            CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
            String varAlgorithm = null;
            if (algorithm != null && !algorithm.isEmpty()){
            	varAlgorithm = algorithm;
            }else{
            	varAlgorithm = "SHA256withRSA";
            }
            	
            SignerInfoGenerator signerInfoGenerator = new JcaSimpleSignerInfoGeneratorBuilder().build(varAlgorithm, privateKey, signCert);
            generator.addSignerInfoGenerator(signerInfoGenerator);

            Store<?> certStore = new JcaCertStore(certList);
            generator.addCertificates(certStore);

//            Store crlStore = new JcaCRLStore(crlList);
//            generator.addCRLs(crlStore);
            // Create the signed data object
            CMSTypedData data = new CMSProcessableByteArray(request);
            CMSSignedData signed = generator.generate(data, true);
            return signed.getEncoded();

        } catch (CMSException | IOException | OperatorCreationException | CertificateEncodingException ex) {
            logger.info(ex.getMessage());
        }
        return null;
    }
 
开发者ID:demoiselle,项目名称:signer,代码行数:45,代码来源:RequestSigner.java


示例10: sign

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public byte[] sign(InputStream content) {
	CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
	// CertificateChain
	List<Certificate> certList = Arrays.asList(certChain);

	try {
		CertStore certStore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList),
				provider);

		Hashtable signedAttrs = new Hashtable();
		X509Certificate signingCert = (X509Certificate) certList.get(0);
		gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC")
				.setSignedAttributeGenerator(new AttributeTable(signedAttrs))
				.build("SHA256withRSA", privKey, signingCert));

		gen.addCertificates(new JcaCertStore(certList));
		// gen.addCRLs(new JcaCRLStore(certStore.getCRLs(null)));
		boolean embedCrls = true;
		if (embedCrls) {
			X509CRL[] crls = fetchCRLs(signingCert);
			for (X509CRL crl : crls) {
				gen.addCRL(new JcaX509CRLHolder(crl));
			}
		}
		// gen.addOtherRevocationInfo(arg0, arg1);

		CMSProcessableByteArray processable = new CMSProcessableByteArray(IOUtils.toByteArray(content));

		CMSSignedData signedData = gen.generate(processable, false);
		if (tsaClient != null) {
			signedData = signTimeStamps(signedData);
		}
		return signedData.getEncoded();
	} catch (Exception e) {
		new RuntimeException(e);
	}
	throw new RuntimeException("Problem while preparing signature");

}
 
开发者ID:beat2,项目名称:pdfbox-signer,代码行数:40,代码来源:Signing.java


示例11: generateMultiPartRsa

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsa(
    String       algorithm,
    MimeBodyPart msg,
    Date         signingTime,
    Map          micalgs)
    throws Exception
{
    List certList = new ArrayList();

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

    Store certs = new JcaCertStore(certList);

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator(micalgs);

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs))).build(algorithm, _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

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


示例12: generateMultiPartRsaPSS

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
    String digest,
    MimeBodyPart msg,
    Date         signingTime)
    throws Exception
{
    List certList = new ArrayList();

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

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

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

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build(digest + "withRSAandMGF1", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

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


示例13: signRequest

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
/**
     * Realiza a assinatura de uma requisicao de carimbo de tempo
     *
     * @param privateKey
     * @param certificates
     * @param request
     * @return A requisicao assinada
     */
    public byte[] signRequest(PrivateKey privateKey, Certificate[] certificates, byte[] request) {
        try {
            logger.info("Efetuando a assinatura da requisicao");
            Security.addProvider(new BouncyCastleProvider());

            X509Certificate signCert = (X509Certificate) certificates[0];
            List<X509Certificate> certList = new ArrayList<>();
            certList.add(signCert);

            // setup the generator
            CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
            SignerInfoGenerator signerInfoGenerator = new JcaSimpleSignerInfoGeneratorBuilder().build("SHA256withRSA", privateKey, signCert);
            generator.addSignerInfoGenerator(signerInfoGenerator);

            Store certStore = new JcaCertStore(certList);
            generator.addCertificates(certStore);

//            Store crlStore = new JcaCRLStore(crlList);
//            generator.addCRLs(crlStore);
            // Create the signed data object
            CMSTypedData data = new CMSProcessableByteArray(request);
            CMSSignedData signed = generator.generate(data, true);
            return signed.getEncoded();

        } catch (CMSException | IOException | OperatorCreationException | CertificateEncodingException ex) {
            logger.info(ex.getMessage());
        }
        return null;
    }
 
开发者ID:humbertopacheco,项目名称:timestamp,代码行数:38,代码来源:RequestSigner.java


示例14: testOutput

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Test
public void testOutput() throws Exception {
    SMIMESignedGenerator gen = new SMIMESignedGenerator();
    SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", privateKey, cert);
    gen.addSignerInfoGenerator(signer);

    MimeMultipart mp = gen.generate(createMsg());

    output(mp);

}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:12,代码来源:SignedTest.java


示例15: create

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public static Signer create(
        final File keystoreFile,
        final String keystorePassword,
        final String signingAlias,
        final String keyPassword) throws IOException,
                                         KeyStoreException,
                                         NoSuchAlgorithmException,
                                         CertificateException,
                                         UnrecoverableKeyException,
                                         OperatorCreationException,
                                         CMSException,
                                         InvalidNameException {
    final KeyStore jksKeyStore = KeyStore.getInstance("JKS");
    final InputStream is = new FileInputStream(keystoreFile);
    try {
        jksKeyStore.load(is, keystorePassword.toCharArray());
    } finally {
        is.close();
    }

    final PrivateKey privateKey =
            (PrivateKey) jksKeyStore.getKey(signingAlias,
                                            keyPassword.toCharArray());
    final Certificate[] certChain =
            jksKeyStore.getCertificateChain(signingAlias);
    if (certChain == null) {
        throw new CertificateException(
                "Certificate chain not found under \"" + signingAlias
                                                       + "\"");
    }

    final X509Certificate signingCert = (X509Certificate) certChain[0];
    final String subjectName = getSubjectName(signingCert);

    Certificate[] certChain2;
    if (certChain.length == 3) { //re-order to match the same order in codesign
        certChain2 = new Certificate[3];
        certChain2[0] = certChain[1];
        certChain2[1] = certChain[2];
        certChain2[2] = certChain[0];
    } else {
        certChain2 = certChain;
    }
    final Store certs = new JcaCertStore(Arrays.asList(certChain2));
    final CMSSignedDataGenerator signatureGenerator =
            new CMSSignedDataGenerator();

    signatureGenerator.addSignerInfoGenerator(
            new JcaSimpleSignerInfoGeneratorBuilder()
                        .setProvider("BC")
                        .build("SHA1withRSA", privateKey, signingCert));
    signatureGenerator.addCertificates(certs);

    return new Signer(signatureGenerator, subjectName);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:56,代码来源:Signer.java


示例16: sign

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
@PublicAtsApi
public Package sign( Package sourcePackage ) throws ActionException {

    try {
        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
            Security.addProvider(new BouncyCastleProvider());
        }

        KeyStore ks = getKeystore();
        PrivateKey privateKey = (PrivateKey) ks.getKey(aliasOrCN, certPassword.toCharArray());
        X509Certificate cer = (X509Certificate) ks.getCertificate(aliasOrCN);

        /* Create the SMIMESignedGenerator */
        SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
        capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
        capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
        capabilities.addCapability(SMIMECapability.dES_CBC);

        ASN1EncodableVector attributes = new ASN1EncodableVector();
        attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(new IssuerAndSerialNumber(new X500Name( (cer).getIssuerDN()
                                                                                                              .getName()),
                                                                                           cer.getSerialNumber())));
        attributes.add(new SMIMECapabilitiesAttribute(capabilities));

        if (signatureAlgorithm == null) {
            signatureAlgorithm = SignatureAlgorithm.DSA.equals(privateKey.getAlgorithm())
                                                                                          ? "SHA1withDSA"
                                                                                          : "MD5withRSA";
        }

        SMIMESignedGenerator signer = new SMIMESignedGenerator();
        JcaSimpleSignerInfoGeneratorBuilder signerGeneratorBuilder = new JcaSimpleSignerInfoGeneratorBuilder();
        signerGeneratorBuilder.setProvider(BouncyCastleProvider.PROVIDER_NAME);
        signerGeneratorBuilder.setSignedAttributeGenerator(new AttributeTable(attributes));
        signer.addSignerInfoGenerator(signerGeneratorBuilder.build(signatureAlgorithm, privateKey,
                                                                   cer));

        /* Add the list of certs to the generator */
        List<X509Certificate> certList = new ArrayList<X509Certificate>();
        certList.add(cer);
        Store<?> certs = new JcaCertStore(certList);
        signer.addCertificates(certs);

        /* Sign the message */
        Session session = Session.getDefaultInstance(System.getProperties(), null);

        MimeMultipart mm = signer.generate(getMimeMessage(sourcePackage));
        MimeMessage signedMessage = new MimeMessage(session);

        /* Set all original MIME headers in the signed message */
        Enumeration<?> headers = getMimeMessage(sourcePackage).getAllHeaderLines();
        while (headers.hasMoreElements()) {
            signedMessage.addHeaderLine((String) headers.nextElement());
        }

        /* Set the content of the signed message */
        signedMessage.setContent(mm);
        signedMessage.saveChanges();

        return new MimePackage(signedMessage);
    } catch (Exception e) {
        throw new ActionException(EXCEPTION_WHILE_SIGNING, e);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:65,代码来源:SMimePackageEncryptor.java


示例17: signMessage

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeBodyPart signMessage(MimeBodyPart bodyPart) throws Exception{
	X509Certificate cert = partnershipDVO.getVerifyX509Certificate();
	
	/* Create the SMIMESignedGenerator */
       SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
       capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
       capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
       capabilities.addCapability(SMIMECapability.dES_CBC);

       ASN1EncodableVector attributes = new ASN1EncodableVector();
       attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(
           new IssuerAndSerialNumber(new X509Name(cert.getIssuerDN().getName()), cert.getSerialNumber()))
       );
       attributes.add(new SMIMECapabilitiesAttribute(capabilities));

       SMIMESignedGenerator signer = new SMIMESignedGenerator();
       signer.setContentTransferEncoding("base64");
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(SECURITY_PROVIDER)
			      .setSignedAttributeGenerator(new AttributeTable(attributes))
			      .build("SHA1withRSA",
				     keyMan.getPrivateKey(),
				     partnershipDVO.getVerifyX509Certificate()));

       // Add the list of certs to the generator
       ArrayList certList = new ArrayList();
       certList.add(cert);
       CertStore certs = CertStore.getInstance("Collection",
               new CollectionCertStoreParameters(certList), "BC");
signer.addCertificates(new JcaCertStore(certList));

       // Sign body part
MimeMultipart mm = signer.generate(bodyPart);

       InternetHeaders headers = new InternetHeaders();
       boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
       headers.setHeader("Content-Type", isContentTypeFolded? mm.getContentType():mm.getContentType().replaceAll("\\s", " "));
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       mm.writeTo(baos);  
       MimeBodyPart signedPart = new MimeBodyPart(headers, baos.toByteArray());
       
       return signedPart;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:43,代码来源:IncomingMessageProcessorTest.java


示例18: testSHA1WithRSANoAttributesSimple

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testSHA1WithRSANoAttributesSimple()
    throws Exception
{
    List              certList = new ArrayList();
    CMSTypedData      msg = new CMSProcessableByteArray("Hello world!".getBytes());

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

    Store           certs = new JcaCertStore(certList);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
    
    JcaSimpleSignerInfoGeneratorBuilder builder = new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setDirectSignature(true);

    gen.addSignerInfoGenerator(builder.build("SHA1withRSA", _origKP.getPrivate(), _origCert));

    gen.addCertificates(certs);

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

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

    verifySignatures(s, md.digest("Hello world!".getBytes()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:NewSignedDataTest.java


示例19: testHeadersEncapsulated

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testHeadersEncapsulated()
    throws Exception
{
    List           certList = new ArrayList();

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

    Store           certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build("SHA1withRSA", _signKP.getPrivate(), _signCert));

    gen.addCertificates(certs);

    MimeBodyPart res = gen.generateEncapsulated(msg);

    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:credentials,项目名称:irma_future_id,代码行数:25,代码来源:NewSMIMESignedTest.java


示例20: generateEncapsulatedRsa

import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder; //导入依赖的package包/类
private MimeBodyPart generateEncapsulatedRsa(String sigAlg, MimeBodyPart msg)
    throws Exception
{
    List certList = new ArrayList();

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

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build(sigAlg, _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Event类代码示例发布时间:2022-05-22
下一篇:
Java Address类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap