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

Java SignerInfoGenerator类代码示例

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

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



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

示例1: createSignedDataGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
private CMSSignedDataGenerator createSignedDataGenerator()
{
	try
	{
		SignerInfoGenerator signerInfoGenerator = createSignerInfoGenerator();
		CMSSignedDataGenerator signedDataGenerator = new CMSSignedDataGenerator();
		signedDataGenerator.addSignerInfoGenerator(signerInfoGenerator);
		signedDataGenerator.addCertificate(inHolder(signerCertificate));
		signedDataGenerator.addCertificate(inHolder(caCertificate));
		return signedDataGenerator;
	}
	catch (CMSException e)
	{
		throw YonaException.unexpected(e);
	}
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:17,代码来源:AppleMobileConfigSigner.java


示例2: createSignerInfoGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
private SignerInfoGenerator createSignerInfoGenerator()
{
	try
	{
		ContentSigner sha1Signer = createContentSigner();

		JcaDigestCalculatorProviderBuilder digestProviderBuilder = new JcaDigestCalculatorProviderBuilder().setProvider("BC");
		JcaSignerInfoGeneratorBuilder signerInfoGeneratorBuilder = new JcaSignerInfoGeneratorBuilder(
				digestProviderBuilder.build());

		return signerInfoGeneratorBuilder.build(sha1Signer, signerCertificate);
	}
	catch (CertificateException | OperatorCreationException e)
	{
		throw YonaException.unexpected(e);
	}
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:18,代码来源:AppleMobileConfigSigner.java


示例3: writeTo

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例4: testOutput2

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例5: testPythonVerified

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例6: testPythonVerifiedBad

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例7: build

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
public SignerInfoGenerator build(String algorithmName, PrivateKey privateKey, X509Certificate certificate)
    throws OperatorCreationException, CertificateEncodingException
{
    ContentSigner contentSigner = helper.createContentSigner(algorithmName, privateKey);

    return configureAndBuild().build(contentSigner, new JcaX509CertificateHolder(certificate));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:JcaSimpleSignerInfoGeneratorBuilder.java


示例8: TimeStampTokenGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
/**
 * basic creation - only the default attributes will be included here.
 * @deprecated use SignerInfoGenerator constructor that takes a digest calculator
 */
public TimeStampTokenGenerator(
    final SignerInfoGenerator     signerInfoGen,
    ASN1ObjectIdentifier          tsaPolicy)
    throws IllegalArgumentException, TSPException
{
    this(new DigestCalculator()
    {
        private ByteArrayOutputStream bOut = new ByteArrayOutputStream();

        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
        }

        public OutputStream getOutputStream()
        {
            return bOut;
        }

        public byte[] getDigest()
        {
            try
            {
                return MessageDigest.getInstance("SHA-1").digest(bOut.toByteArray());
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new IllegalStateException("cannot find sha-1: "+ e.getMessage());
            }
        }
    }, signerInfoGen, tsaPolicy);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:37,代码来源:TimeStampTokenGenerator.java


示例9: signRequest

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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: createCMSSignedDataGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
/**
 * Note:
 * Section 5.1 of RFC 3852 [4] requires that, the CMS SignedData version be set to 3 if certificates from
 * SignedData is present AND (any version 1 attribute certificates are present OR any SignerInfo structures
 * are version 3 OR eContentType from encapContentInfo is other than id-data). Otherwise, the CMS
 * SignedData version is required to be set to 1.
 * ---> CMS SignedData Version is handled automatically by BouncyCastle.
 *
 * @param parameters
 *            set of the driving signing parameters
 * @param contentSigner
 *            the contentSigned to get the hash of the data to be signed
 * @param signerInfoGeneratorBuilder
 *            true if the unsigned attributes must be included
 * @param originalSignedData
 *            the original signed data if extending an existing signature. null otherwise.
 * @return the bouncycastle signed data generator which signs the document and adds the required signed and unsigned
 *         CMS attributes
 * @throws eu.europa.esig.dss.DSSException
 */
protected CMSSignedDataGenerator createCMSSignedDataGenerator(final CAdESSignatureParameters parameters, final ContentSigner contentSigner,
		final SignerInfoGeneratorBuilder signerInfoGeneratorBuilder, final CMSSignedData originalSignedData) throws DSSException {
	try {

		final CertificateToken signingCertificate = parameters.getSigningCertificate();

		final CMSSignedDataGenerator generator = new CMSSignedDataGenerator();

		final X509CertificateHolder certHolder = DSSASN1Utils.getX509CertificateHolder(signingCertificate);
		final SignerInfoGenerator signerInfoGenerator = signerInfoGeneratorBuilder.build(contentSigner, certHolder);

		generator.addSignerInfoGenerator(signerInfoGenerator);

		final List<CertificateToken> certificateChain = new LinkedList<CertificateToken>();
		if (originalSignedData != null) {

			generator.addSigners(originalSignedData.getSignerInfos());
			generator.addAttributeCertificates(originalSignedData.getAttributeCertificates());
			generator.addCRLs(originalSignedData.getCRLs());
			generator.addOtherRevocationInfo(id_pkix_ocsp_basic, originalSignedData.getOtherRevocationInfo(id_pkix_ocsp_basic));
			generator.addOtherRevocationInfo(id_ri_ocsp_response, originalSignedData.getOtherRevocationInfo(id_ri_ocsp_response));

			final Store<X509CertificateHolder> certificates = originalSignedData.getCertificates();
			final Collection<X509CertificateHolder> certificatesMatches = certificates.getMatches(null);
			for (final X509CertificateHolder certificatesMatch : certificatesMatches) {
				final CertificateToken token = DSSASN1Utils.getCertificate(certificatesMatch);
				if (!certificateChain.contains(token)) {
					certificateChain.add(token);
				}
			}
		}

		final JcaCertStore jcaCertStore = getJcaCertStore(certificateChain, parameters);
		generator.addCertificates(jcaCertStore);
		return generator;
	} catch (CMSException | OperatorCreationException e) {
		throw new DSSException(e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:60,代码来源:CMSSignedDataBuilder.java


示例11: signRequest

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例12: testOutput

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的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


示例13: build

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
public SignerInfoGenerator build(ContentSigner contentSigner, X509CertificateHolder certHolder)
    throws OperatorCreationException
{
    return builder.build(contentSigner, certHolder);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:6,代码来源:JcaSignerInfoGeneratorBuilder.java


示例14: addSignerInfoGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
public void addSignerInfoGenerator(SignerInfoGenerator sigInfoGen)
{
    signerInfoGens.add(sigInfoGen);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:5,代码来源:SMIMESignedGenerator.java


示例15: addHashHeader

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
private void addHashHeader(
    StringBuffer header,
    List         signers)
{
    int                 count = 0;
    
    //
    // build the hash header
    //
    Iterator   it = signers.iterator();
    Set        micAlgSet = new TreeSet();
    
    while (it.hasNext())
    {
        Object              signer = it.next();
        ASN1ObjectIdentifier digestOID;

        if (signer instanceof Signer)
        {
            digestOID = ((Signer)signer).getDigestOID();
        }
        else if (signer instanceof SignerInformation)
        {
            digestOID = ((SignerInformation)signer).getDigestAlgorithmID().getAlgorithm();
        }
        else
        {
            digestOID = ((SignerInfoGenerator)signer).getDigestAlgorithm().getAlgorithm();
        }

        String micAlg = (String)micAlgs.get(digestOID);

        if (micAlg == null)
        {
            micAlgSet.add("unknown");
        }
        else
        {
            micAlgSet.add(micAlg);
        }
    }
    
    it = micAlgSet.iterator();
    
    while (it.hasNext())
    {
        String    alg = (String)it.next();

        if (count == 0)
        {
            if (micAlgSet.size() != 1)
            {
                header.append("; micalg=\"");
            }
            else
            {
                header.append("; micalg=");
            }
        }
        else
        {
            header.append(',');
        }

        header.append(alg);

        count++;
    }

    if (count != 0)
    {
        if (micAlgSet.size() != 1)
        {
            header.append('\"');
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:78,代码来源:SMIMESignedGenerator.java


示例16: getGenerator

import org.bouncycastle.cms.SignerInfoGenerator; //导入依赖的package包/类
protected CMSSignedDataStreamGenerator getGenerator()
    throws CMSException, CertStoreException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException
{
    CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator();
    
    for (Iterator it = _certStores.iterator(); it.hasNext();)
    {
        gen.addCertificatesAndCRLs((CertStore)it.next());
    }

    for (Iterator it = certStores.iterator(); it.hasNext();)
    {
        gen.addCertificates((Store)it.next());
    }

    for (Iterator it = crlStores.iterator(); it.hasNext();)
    {
        gen.addCRLs((Store)it.next());
    }

    for (Iterator it = attrCertStores.iterator(); it.hasNext();)
    {
        gen.addAttributeCertificates((Store)it.next());
    }

    for (Iterator it = _attributeCerts.iterator(); it.hasNext();)
    {
        gen.addAttributeCertificates((X509Store)it.next());
    }

    for (Iterator it = _signers.iterator(); it.hasNext();)
    {
        Signer signer = (Signer)it.next();

        if (signer.getEncryptionOID() != null)
        {
            gen.addSigner(signer.getKey(), signer.getCert(), signer.getEncryptionOID().getId(), signer.getDigestOID().getId(), signer.getSignedAttr(), signer.getUnsignedAttr(), provider);
        }
        else
        {
            gen.addSigner(signer.getKey(), signer.getCert(), signer.getDigestOID().getId(), signer.getSignedAttr(), signer.getUnsignedAttr(), provider);
        }
    }

    for (Iterator it = signerInfoGens.iterator(); it.hasNext();)
    {
        gen.addSignerInfoGenerator((SignerInfoGenerator)it.next());
    }

    gen.addSigners(new SignerInformationStore(_oldSigners));
    
    return gen;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:54,代码来源:SMIMESignedGenerator.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java DatagramSocket类代码示例发布时间:2022-05-22
下一篇:
Java EventDispatcher类代码示例发布时间: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