本文整理汇总了Java中org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcaSignerInfoGeneratorBuilder类的具体用法?Java JcaSignerInfoGeneratorBuilder怎么用?Java JcaSignerInfoGeneratorBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JcaSignerInfoGeneratorBuilder类属于org.bouncycastle.cms.jcajce包,在下文中一共展示了JcaSignerInfoGeneratorBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateP7B
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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);
}
}
示例2: testCMSSignature
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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);
}
示例3: sign
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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);
}
}
示例4: sign
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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();
}
示例5: createSignerInfoGenerator
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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);
}
}
示例6: sign
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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();
}
示例7: writeSignatureBlock
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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();
}
示例8: writeSignatureBlock
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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();
}
示例9: writeSignatureBlock
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的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());
}
示例10: toSignedData
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
private CMSSignedData toSignedData()
throws CertificateEncodingException,
OperatorCreationException, CMSException,
InvalidKeyException, SignatureException,
NoSuchAlgorithmException, NoSuchProviderException {
if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
List<X509Certificate> certList = new ArrayList<X509Certificate>();
CMSTypedData msg = new CMSProcessableByteArray(Xml.this
.toString().getBytes(Charsets.UTF_8));
certList.add(signCert);
@SuppressWarnings("unchecked")
Store<X509Certificate> certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner signer = new JcaContentSignerBuilder(
BouncyCastleWsaaManager.SIGNING_ALGORITHM)
.setProvider("BC").build(privateKey);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider(
"BC").build()).build(signer, signCert));
gen.addCertificates(certs);
return gen.generate(msg, true);
}
示例11: sign
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
@Override
public byte[] sign(InputStream is) throws SignatureException, IOException {
try {
BouncyCastleProvider BC = new BouncyCastleProvider();
Store<?> certStore = new JcaCertStore(Collections.singletonList(certificate));
CMSTypedDataInputStream input = new CMSTypedDataInputStream(is);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha512Signer = new JcaContentSignerBuilder("SHA256WithRSA").setProvider(BC).build(privateKey);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()).build(sha512Signer, new X509CertificateHolder(certificate.getEncoded())
));
gen.addCertificates(certStore);
CMSSignedData signedData = gen.generate(input, false);
if (der)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DEROutputStream dos = new DEROutputStream(baos);
dos.writeObject(signedData.toASN1Structure());
return baos.toByteArray();
}
else
return signedData.getEncoded();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例12: testCertOrdering1
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testCertOrdering1()
throws Exception
{
List certList = new ArrayList();
CMSTypedData msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_origCert);
certList.add(_signCert);
certList.add(_signDsaCert);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(_origKP.getPrivate());
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()).build(sha1Signer, _origCert));
gen.addCertificates(certs);
CMSSignedData sd = gen.generate(msg, true);
certs = sd.getCertificates();
Iterator it = certs.getMatches(null).iterator();
assertEquals(new JcaX509CertificateHolder(_origCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signDsaCert), it.next());
}
示例13: testCertOrdering2
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testCertOrdering2()
throws Exception
{
List certList = new ArrayList();
CMSTypedData msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_signCert);
certList.add(_signDsaCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(_origKP.getPrivate());
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()).build(sha1Signer, _origCert));
gen.addCertificates(certs);
CMSSignedData sd = gen.generate(msg, true);
certs = sd.getCertificates();
Iterator it = certs.getMatches(null).iterator();
assertEquals(new JcaX509CertificateHolder(_signCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signDsaCert), it.next());
assertEquals(new JcaX509CertificateHolder(_origCert), it.next());
}
示例14: testCertOrdering1
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testCertOrdering1()
throws Exception
{
List certList = new ArrayList();
CMSTypedData msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_origCert);
certList.add(_signCert);
certList.add(_signDsaCert);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(_origKP.getPrivate());
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()).build(sha1Signer, _origCert));
gen.addCertificates(certs);
CMSSignedData sd = gen.generate(msg, true);
certs = sd.getCertificates();
Iterator it = certs.getMatches(null).iterator();
assertEquals(new JcaX509CertificateHolder(_origCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signDsaCert), it.next());
}
示例15: testCertOrdering2
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; //导入依赖的package包/类
public void testCertOrdering2()
throws Exception
{
List certList = new ArrayList();
CMSTypedData msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_signCert);
certList.add(_signDsaCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(_origKP.getPrivate());
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()).build(sha1Signer, _origCert));
gen.addCertificates(certs);
CMSSignedData sd = gen.generate(msg, true);
certs = sd.getCertificates();
Iterator it = certs.getMatches(null).iterator();
assertEquals(new JcaX509CertificateHolder(_signCert), it.next());
assertEquals(new JcaX509CertificateHolder(_signDsaCert), it.next());
assertEquals(new JcaX509CertificateHolder(_origCert), it.next());
}