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


Java CMSSignedDataGenerator.generate方法代码示例

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


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

示例1: generateP7B

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public CMSSignedData generateP7B(X509CertificateHolder caCertificate, PrivateKey caPrivateKey) {
	try {
		List<X509CertificateHolder> certChain = new ArrayList<X509CertificateHolder>();
		certChain.add(caCertificate);

		Store certs = new JcaCertStore(certChain);

		CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
		ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BouncyCastleProvider.PROVIDER_NAME).build(caPrivateKey);

		cmsSignedDataGenerator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
				new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build())
		.build(sha1Signer, caCertificate));
		cmsSignedDataGenerator.addCertificates(certs);

		CMSTypedData chainMessage = new CMSProcessableByteArray("chain".getBytes());
		CMSSignedData sigData = cmsSignedDataGenerator.generate(chainMessage, false);

		return sigData;
		
	} catch(Exception e) {
		throw new RuntimeException("Error while generating certificate chain: " + e.getMessage(), e);
	}
}
 
开发者ID:fabiusks,项目名称:cert-services,代码行数:25,代码来源:P7BService.java

示例2: generateSignatureBlock

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private static byte[] generateSignatureBlock(
        SignerConfig signerConfig, byte[] signatureFileBytes)
                throws InvalidKeyException, CertificateEncodingException, SignatureException {
    JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
    X509Certificate signerCert = signerConfig.certificates.get(0);
    String jcaSignatureAlgorithm =
            getJcaSignatureAlgorithm(
                    signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
    try {
        ContentSigner signer =
                new JcaContentSignerBuilder(jcaSignatureAlgorithm)
                .build(signerConfig.privateKey);
        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
        gen.addSignerInfoGenerator(
                new SignerInfoGeneratorBuilder(
                        new JcaDigestCalculatorProviderBuilder().build(),
                        SignerInfoSignatureAlgorithmFinder.INSTANCE)
                        .setDirectSignature(true)
                        .build(signer, new JcaX509CertificateHolder(signerCert)));
        gen.addCertificates(certs);

        CMSSignedData sigData =
                gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
            DEROutputStream dos = new DEROutputStream(out);
            dos.writeObject(asn1.readObject());
        }
        return out.toByteArray();
    } catch (OperatorCreationException | CMSException | IOException e) {
        throw new SignatureException("Failed to generate signature", e);
    }
}
 
开发者ID:Meituan-Dianping,项目名称:walle,代码行数:35,代码来源:V1SchemeSigner.java

示例3: generateSignatureBlock

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private static byte[] generateSignatureBlock(SignerConfig signerConfig, byte[] signatureFileBytes) throws InvalidKeyException, CertificateEncodingException, SignatureException {
	JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
	X509Certificate signerCert = signerConfig.certificates.get(0);
	String jcaSignatureAlgorithm = getJcaSignatureAlgorithm(signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
	try {
		ContentSigner signer = new JcaContentSignerBuilder(jcaSignatureAlgorithm).build(signerConfig.privateKey);
		CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
		gen.addSignerInfoGenerator(new SignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build(), SignerInfoSignatureAlgorithmFinder.INSTANCE).setDirectSignature(true).build(signer,
				new JcaX509CertificateHolder(signerCert)));
		gen.addCertificates(certs);

		CMSSignedData sigData = gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
			DEROutputStream dos = new DEROutputStream(out);
			dos.writeObject(asn1.readObject());
		}
		return out.toByteArray();
	} catch (OperatorCreationException | CMSException | IOException e) {
		throw new SignatureException("Failed to generate signature", e);
	}
}
 
开发者ID:abutun,项目名称:apk-verifier,代码行数:24,代码来源:V1SchemeSigner.java

示例4: preSign

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
public DigestInfo preSign(List<DigestInfo> digestInfos, List<X509Certificate> signingCertificateChain,
		IdentityDTO identity, AddressDTO address, byte[] photo) throws NoSuchAlgorithmException {
	CMSSignedDataGenerator generator = createCMSSignedDataGenerator(signingCertificateChain);
	byte[] toBeSigned = getToBeSigned();
	CMSProcessable content = new CMSProcessableByteArray(toBeSigned);

	CMSProvider provider = new CMSProvider();
	SHA1WithRSAProxySignature.reset();
	try {
		generator.generate(content, true, provider);
	} catch (CMSException e) {
		throw new RuntimeException(e);
	}
	byte[] digestValue = SHA1WithRSAProxySignature.getDigestValue();
	String description = getSignatureDescription();
	DigestInfo digestInfo = new DigestInfo(digestValue, "SHA1", description);
	return digestInfo;
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:19,代码来源:AbstractCMSSignatureService.java

示例5: testVerifySignature

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
@Test(description = "This test case tests Signature verification of a Certificate against the keystore")
public void testVerifySignature() throws KeystoreException, CertificateEncodingException, CMSException, IOException {
    BASE64Encoder encoder = new BASE64Encoder();
    //generate and save a certificate in the keystore
    X509Certificate x509Certificate = managementService.generateX509Certificate();
    //Generate CMSdata
    CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
    List<X509Certificate> list = new ArrayList<>();
    list.add(x509Certificate);
    JcaCertStore store = new JcaCertStore(list);
    generator.addCertificates(store);
    CMSSignedData degenerateSd = generator.generate(new CMSAbsentContent());
    byte[] signature = degenerateSd.getEncoded();
    boolean verifySignature = managementService.verifySignature(encoder.encode(signature));
    Assert.assertNotNull(verifySignature);
    Assert.assertTrue(verifySignature);
    log.info("VerifySignature Test Successful");
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:19,代码来源:CertificateManagementServiceImplTests.java

示例6: testExtractCertificateFromSignature

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
@Test(description = "This test case tests extracting Certificate from the header Signature")
public void testExtractCertificateFromSignature() throws KeystoreException, CertificateEncodingException, CMSException, IOException {
    BASE64Encoder encoder = new BASE64Encoder();
    //generate and save a certificate in the keystore
    X509Certificate x509Certificate = managementService.generateX509Certificate();
    //Generate CMSdata
    CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
    List<X509Certificate> list = new ArrayList<>();
    list.add(x509Certificate);
    JcaCertStore store = new JcaCertStore(list);
    generator.addCertificates(store);
    CMSSignedData degenerateSd = generator.generate(new CMSAbsentContent());
    byte[] signature = degenerateSd.getEncoded();
    X509Certificate certificate = managementService.extractCertificateFromSignature(encoder.encode(signature));
    Assert.assertNotNull(certificate);
    Assert.assertEquals(certificate.getType(), CertificateManagementConstants.X_509);
    log.info("ExtractCertificateFromSignature Test Successful");
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:19,代码来源:CertificateManagementServiceImplTests.java

示例7: testCMSSignature

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
@Test
public void testCMSSignature() throws Exception {
	Security.addProvider(new BeIDProvider());
	Security.addProvider(new BouncyCastleProvider());

	KeyStore keyStore = KeyStore.getInstance("BeID");
	keyStore.load(null);
	PrivateKey privateKey = (PrivateKey) keyStore.getKey("Authentication",
			null);
	X509Certificate certificate = (X509Certificate) keyStore
			.getCertificate("Authentication");

	CMSTypedData msg = new CMSProcessableByteArray(
			"Hello world!".getBytes());

	CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
	ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA")
			.build(privateKey);

	gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
			new JcaDigestCalculatorProviderBuilder().setProvider("BC")
					.build()).build(sha1Signer, certificate));

	CMSSignedData sigData = gen.generate(msg, false);
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:26,代码来源:CMSTest.java

示例8: sign

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private byte[] sign(byte[] data) throws SignatureException {
	CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
	try {
		ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withRSA").build(this.privateKey);
		cmsSignedDataGenerator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
				new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build())
						.build(contentSigner, this.certificateChain.get(0)));
		for (X509Certificate certificate : this.certificateChain) {
			cmsSignedDataGenerator.addCertificate(new X509CertificateHolder(certificate.getEncoded()));
		}
		CMSTypedData cmsTypedData = new CMSProcessableByteArray(data);
		CMSSignedData cmsSignedData = cmsSignedDataGenerator.generate(cmsTypedData, true);
		return cmsSignedData.getEncoded();
	} catch (Exception e) {
		throw new SignatureException(e);
	}
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:18,代码来源:CMSSigner.java

示例9: sign

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private byte[] sign(byte[] data, boolean includeCertificate)
		throws OperatorCreationException, CertificateEncodingException,
		CMSException, IOException {
	CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
	ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256WITHRSAANDMGF1")
			.build(this.authenticationPrivateKey);
	cmsSignedDataGenerator
			.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
					new JcaDigestCalculatorProviderBuilder().build())
					.build(contentSigner, this.authenticationCertificate));
	if (includeCertificate) {
		cmsSignedDataGenerator.addCertificate(new X509CertificateHolder(
				this.authenticationCertificate.getEncoded()));
	}
	CMSTypedData cmsTypedData = new CMSProcessableByteArray(data);
	CMSSignedData cmsSignedData = cmsSignedDataGenerator.generate(
			cmsTypedData, true);
	return cmsSignedData.getEncoded();
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:20,代码来源:Sealer.java

示例10: sign

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
@Override
public byte[] sign(byte[] data) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    KeyStore inStore = KeyStore.getInstance("PKCS12");
    inStore.load(new FileInputStream(packageZipConfiguration.pushPackageSignerCertPath), packageZipConfiguration.pushPackageSignerCertPassword.toCharArray());

    Key key = inStore.getKey(packageZipConfiguration.pushPackageSignerCertName, packageZipConfiguration.pushPackageSignerCertPassword.toCharArray());
    PrivateKey privateKey = RSAPrivateKeyImpl.parseKey(new DerValue(key.getEncoded()));
    Certificate certificate = inStore.getCertificate(packageZipConfiguration.pushPackageSignerCertName);
    X509CertificateHolder certificateHolder = new X509CertificateHolder(certificate.getEncoded());

    List certList = new ArrayList();
    CMSTypedData msg = new CMSProcessableByteArray(data); //Data to sign

    certList.add(certificateHolder); //Adding the X509 Certificate

    Store certs = new JcaCertStore(certList);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
    //Initializing the the BC's Signer
    ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);

    gen.addSignerInfoGenerator(
            new JcaSignerInfoGeneratorBuilder(
                    new JcaDigestCalculatorProviderBuilder().setProvider("BC").build())
                    .build(sha1Signer, certificateHolder));
    //adding the certificate
    gen.addCertificates(certs);
    //Getting the signed data
    CMSSignedData sigData = gen.generate(msg, false);
    return sigData.getEncoded();
}
 
开发者ID:chriskearney,项目名称:stickypunch,代码行数:33,代码来源:PackageZipSigner.java

示例11: buildSignedData

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private SignedData buildSignedData(X509Certificate cert) throws OperationException {
    CMSSignedDataGenerator cmsSignedDataGen = new CMSSignedDataGenerator();
    try {
        X509CertificateHolder certHolder = new X509CertificateHolder(cert.getEncoded());
        cmsSignedDataGen.addCertificate(certHolder);
        if (control.includeCaCert()) {
            refreshCa();
            cmsSignedDataGen.addCertificate(caCert.certHolder());
        }
        CMSSignedData signedData = cmsSignedDataGen.generate(new CMSAbsentContent());
        return SignedData.getInstance(signedData.toASN1Structure().getContent());
    } catch (CMSException | IOException | CertificateEncodingException ex) {
        LogUtil.error(LOG, ex);
        throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex);
    }
}
 
开发者ID:xipki,项目名称:xipki,代码行数:17,代码来源:ScepImpl.java

示例12: getCrl

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
private SignedData getCrl(X509Ca ca, BigInteger serialNumber)
        throws FailInfoException, OperationException {
    if (!control.supportGetCrl()) {
        throw FailInfoException.BAD_REQUEST;
    }

    CertificateList crl = ca.getBcCurrentCrl();
    if (crl == null) {
        throw FailInfoException.BAD_REQUEST;
    }
    CMSSignedDataGenerator cmsSignedDataGen = new CMSSignedDataGenerator();
    cmsSignedDataGen.addCRL(new X509CRLHolder(crl));

    CMSSignedData signedData;
    try {
        signedData = cmsSignedDataGen.generate(new CMSAbsentContent());
    } catch (CMSException ex) {
        LogUtil.error(LOG, ex, "could not generate CMSSignedData");
        throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex);
    }
    return SignedData.getInstance(signedData.toASN1Structure().getContent());
}
 
开发者ID:xipki,项目名称:xipki,代码行数:23,代码来源:ScepImpl.java

示例13: writeSignatureBlock

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
/**
 * Write the certificate file with a digital signature.
 */
private void writeSignatureBlock(CMSTypedData data,
                                 X509Certificate publicKey,
                                 PrivateKey privateKey) throws IOException, CertificateEncodingException, OperatorCreationException, CMSException {

    ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
    certList.add(publicKey);
    JcaCertStore certs = new JcaCertStore(certList);

    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
    ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1with" +
                                                                   privateKey.getAlgorithm()).build(
            privateKey);
    gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder()
                                                                         .build()).setDirectSignature(
            true).build(sha1Signer, publicKey));
    gen.addCertificates(certs);
    CMSSignedData sigData = gen.generate(data, false);

    ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
    DEROutputStream dos = new DEROutputStream(mOutputJar);
    dos.writeObject(asn1.readObject());

    dos.flush();
    dos.close();
    asn1.close();
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:30,代码来源:LocalSignedJarBuilder.java

示例14: writeSignatureBlock

import org.bouncycastle.cms.CMSSignedDataGenerator; //导入方法依赖的package包/类
/** Sign data and write the digital signature to 'out'. */
private static void writeSignatureBlock(
    CMSTypedData data, X509Certificate publicKey, PrivateKey privateKey,
    OutputStream out)
throws IOException,
CertificateEncodingException,
OperatorCreationException,
CMSException {
    ArrayList < X509Certificate > certList = new ArrayList < > (1);
    certList.add(publicKey);
    JcaCertStore certs = new JcaCertStore(certList);
    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
    ContentSigner signer = new JcaContentSignerBuilder(getSignatureAlgorithm(publicKey))
        .setProvider(sBouncyCastleProvider)
        .build(privateKey);
    gen.addSignerInfoGenerator(
        new JcaSignerInfoGeneratorBuilder(
            new JcaDigestCalculatorProviderBuilder()
            .setProvider(sBouncyCastleProvider)
            .build())
        .setDirectSignature(true)
        .build(signer, publicKey));
    gen.addCertificates(certs);
    CMSSignedData sigData = gen.generate(data, false);
    ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
    DEROutputStream dos = new DEROutputStream(out);
    dos.writeObject(asn1.readObject());
}
 
开发者ID:bhb27,项目名称:isu,代码行数:29,代码来源:ZipUtils.java

示例15: signRequest

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


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