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


Java JcaSimpleSignerInfoGeneratorBuilder类代码示例

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


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


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