本文整理汇总了Java中org.bouncycastle.cms.CMSProcessableByteArray类的典型用法代码示例。如果您正苦于以下问题:Java CMSProcessableByteArray类的具体用法?Java CMSProcessableByteArray怎么用?Java CMSProcessableByteArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CMSProcessableByteArray类属于org.bouncycastle.cms包,在下文中一共展示了CMSProcessableByteArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateP7B
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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: generateSignatureBlock
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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);
}
}
示例3: PKIArchiveControlBuilder
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
/**
* Basic constructor - specify the contents of the PKIArchiveControl structure.
*
* @param privateKeyInfo the private key to be archived.
* @param generalName the general name to be associated with the private key.
*/
public PKIArchiveControlBuilder(PrivateKeyInfo privateKeyInfo, GeneralName generalName)
{
EncKeyWithID encKeyWithID = new EncKeyWithID(privateKeyInfo, generalName);
try
{
this.keyContent = new CMSProcessableByteArray(CRMFObjectIdentifiers.id_ct_encKeyWithID, encKeyWithID.getEncoded());
}
catch (IOException e)
{
throw new IllegalStateException("unable to encode key and general name info");
}
this.envGen = new CMSEnvelopedDataGenerator();
}
示例4: addEncryptedData
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
private PKCS12PfxPduBuilder addEncryptedData(OutputEncryptor dataEncryptor, ASN1Sequence data)
throws IOException
{
CMSEncryptedDataGenerator envGen = new CMSEncryptedDataGenerator();
try
{
dataVector.add(envGen.generate(new CMSProcessableByteArray(data.getEncoded()), dataEncryptor).toASN1Structure());
}
catch (CMSException e)
{
throw new PKCSIOException(e.getMessage(), e.getCause());
}
return this;
}
示例5: signFile
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
private static void signFile(Manifest manifest, JarFile inputJar,
X509Certificate publicKey, PrivateKey privateKey,
JarOutputStream outputJar)
throws Exception {
// Assume the certificate is valid for at least an hour.
long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
// MANIFEST.MF
JarEntry je = new JarEntry(JarFile.MANIFEST_NAME);
je.setTime(timestamp);
outputJar.putNextEntry(je);
manifest.write(outputJar);
je = new JarEntry(CERT_SF_NAME);
je.setTime(timestamp);
outputJar.putNextEntry(je);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeSignatureFile(manifest, baos, getDigestAlgorithm(publicKey));
byte[] signedData = baos.toByteArray();
outputJar.write(signedData);
// CERT.{EC,RSA} / CERT#.{EC,RSA}
final String keyType = publicKey.getPublicKey().getAlgorithm();
je = new JarEntry(String.format(CERT_SIG_NAME, keyType));
je.setTime(timestamp);
outputJar.putNextEntry(je);
writeSignatureBlock(new CMSProcessableByteArray(signedData),
publicKey, privateKey, outputJar);
}
示例6: generateSignatureBlock
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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);
}
}
示例7: preSign
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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;
}
示例8: getDataToSign
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
@Override
public ToBeSigned getDataToSign(final DSSDocument toSignDocument, final CAdESSignatureParameters parameters) throws DSSException {
assertSigningDateInCertificateValidityRange(parameters);
final SignaturePackaging packaging = parameters.getSignaturePackaging();
assertSignaturePackaging(packaging);
final SignatureAlgorithm signatureAlgorithm = parameters.getSignatureAlgorithm();
final CustomContentSigner customContentSigner = new CustomContentSigner(signatureAlgorithm.getJCEId());
final SignerInfoGeneratorBuilder signerInfoGeneratorBuilder = cmsSignedDataBuilder.getSignerInfoGeneratorBuilder(parameters, false);
final CMSSignedData originalCmsSignedData = getCmsSignedData(toSignDocument, parameters);
final CMSSignedDataGenerator cmsSignedDataGenerator = cmsSignedDataBuilder.createCMSSignedDataGenerator(parameters, customContentSigner,
signerInfoGeneratorBuilder, originalCmsSignedData);
final DSSDocument toSignData = getToSignData(toSignDocument, parameters, originalCmsSignedData);
final CMSProcessableByteArray content = new CMSProcessableByteArray(DSSUtils.toByteArray(toSignData));
final boolean encapsulate = !SignaturePackaging.DETACHED.equals(packaging);
CMSUtils.generateCMSSignedData(cmsSignedDataGenerator, content, encapsulate);
final byte[] bytes = customContentSigner.getOutputStream().toByteArray();
return new ToBeSigned(bytes);
}
示例9: testCMSSignature
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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);
}
示例10: sign
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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);
}
}
示例11: encrypt
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
private byte[] encrypt(byte[] data) throws CertificateEncodingException,
CMSException, IOException {
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
for (X509Certificate destinationCertificate : this.destinationCertificates) {
cmsEnvelopedDataGenerator
.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(
destinationCertificate)
.setProvider(BouncyCastleProvider.PROVIDER_NAME));
}
CMSTypedData cmsTypedData = new CMSProcessableByteArray(data);
CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator.generate(
cmsTypedData,
new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC)
.setProvider(BouncyCastleProvider.PROVIDER_NAME)
.build());
return cmsEnvelopedData.getEncoded();
}
示例12: sign
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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();
}
示例13: CMSSignature
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
public CMSSignature(byte[] signedData, byte[] cmsSignature) throws InvalidCmsSignatureException {
try {
if (signedData == null || signedData.length < 1) {
throw new InvalidCmsSignatureException("CMS signature signed data is null or empty array");
}
if (cmsSignature == null || cmsSignature.length < 1) {
throw new InvalidCmsSignatureException("CMS signature is null or empty array");
}
CMSProcessableByteArray cmsProcessable = new CMSProcessableByteArray(signedData);
CMSSignedData cmsSignedData = new CMSSignedData(cmsProcessable, cmsSignature);
this.signerInformationStore = cmsSignedData.getSignerInfos();
this.signedDataCertificates = cmsSignedData.getCertificates();
LOGGER.debug("CMS signature contains {} signer information elements", signerInformationStore.size());
} catch (CMSException e) {
throw new InvalidCmsSignatureException("Invalid CMS signature", e);
}
}
示例14: TabeliaoAssinaturaPKCS7
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的package包/类
/**
* Construtor para conteudo e assinatura
*
* @param conteudo -> InputStream
* @param assinatura -> InputStream
* @see InputStream
* @throws CMSException
* @throws IOException
*/
public TabeliaoAssinaturaPKCS7(InputStream conteudo, InputStream assinatura) throws CMSException, IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int read;
while((read = conteudo.read(buffer)) > 0) {
bos.write(buffer, 0, read);
}
buffer = bos.toByteArray();
CMSProcessableByteArray data = new CMSProcessableByteArray(buffer);
signedData = new CMSSignedData(data, assinatura);
}
示例15: sign
import org.bouncycastle.cms.CMSProcessableByteArray; //导入依赖的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();
}