本文整理汇总了Java中org.bouncycastle.cms.DefaultSignedAttributeTableGenerator类的典型用法代码示例。如果您正苦于以下问题:Java DefaultSignedAttributeTableGenerator类的具体用法?Java DefaultSignedAttributeTableGenerator怎么用?Java DefaultSignedAttributeTableGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultSignedAttributeTableGenerator类属于org.bouncycastle.cms包,在下文中一共展示了DefaultSignedAttributeTableGenerator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setSignedAttributeGenerator
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
/**
* set up a DefaultSignedAttributeTableGenerator primed with the passed in AttributeTable.
*
* @param attrTable table of attributes for priming generator
* @return this.
*/
public JcaSimpleSignerInfoGeneratorBuilder setSignedAttributeGenerator(AttributeTable attrTable)
{
this.signedGen = new DefaultSignedAttributeTableGenerator(attrTable);
return this;
}
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:JcaSimpleSignerInfoGeneratorBuilder.java
示例2: signWithSeparatedHashing
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/41767351/create-pkcs7-signature-from-file-digest">
* Create pkcs7 signature from file digest
* </a>
* <p>
* The OP's <code>sign</code> method after fixing some errors. The
* OP's original method is {@link #signBySnox(InputStream)}. The
* errors were
* </p>
* <ul>
* <li>multiple attempts at reading the {@link InputStream} parameter;
* <li>convoluted creation of final CMS container.
* </ul>
* <p>
* Additionally this method uses SHA256 instead of SHA-1.
* </p>
*/
public byte[] signWithSeparatedHashing(InputStream content) throws IOException
{
try
{
// Digest generation step
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] digest = md.digest(IOUtils.toByteArray(content));
// Separate signature container creation step
List<Certificate> certList = Arrays.asList(chain);
JcaCertStore certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
Attribute attr = new Attribute(CMSAttributes.messageDigest,
new DERSet(new DEROctetString(digest)));
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
SignerInfoGeneratorBuilder builder = new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));
AlgorithmIdentifier sha256withRSA = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA");
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(chain[0].getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
gen.addSignerInfoGenerator(builder.build(
new BcRSAContentSignerBuilder(sha256withRSA,
new DefaultDigestAlgorithmIdentifierFinder().find(sha256withRSA))
.build(PrivateKeyFactory.createKey(pk.getEncoded())),
new JcaX509CertificateHolder(cert)));
gen.addCertificates(certs);
CMSSignedData s = gen.generate(new CMSAbsentContent(), false);
return s.getEncoded();
}
catch (Exception e)
{
e.printStackTrace();
throw new IOException(e);
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:65,代码来源:CreateSignature.java
示例3: getSignerInfoGeneratorBuilder
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
/**
* @param signedAttributes
* the signedAttributes
* @param unsignedAttributes
* the unsignedAttributes
* @return a SignerInfoGeneratorBuilder that generate the signed and unsigned attributes according to the parameters
*/
private SignerInfoGeneratorBuilder getSignerInfoGeneratorBuilder(AttributeTable signedAttributes, AttributeTable unsignedAttributes) {
if ((signedAttributes != null) && (signedAttributes.size() == 0)) {
signedAttributes = null;
}
final DefaultSignedAttributeTableGenerator signedAttributeGenerator = new DefaultSignedAttributeTableGenerator(signedAttributes);
if ((unsignedAttributes != null) && (unsignedAttributes.size() == 0)) {
unsignedAttributes = null;
}
final SimpleAttributeTableGenerator unsignedAttributeGenerator = new SimpleAttributeTableGenerator(unsignedAttributes);
return getSignerInfoGeneratorBuilder(signedAttributeGenerator, unsignedAttributeGenerator);
}
开发者ID:esig,项目名称:dss,代码行数:21,代码来源:CMSSignedDataBuilder.java
示例4: addSigner
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
/**
* Adiciona o assinante, nenhum outro atributo alem do padrao serao providos aqui
*
* @param key
* @param cert
* @param digestOID
* @throws IllegalArgumentException
*/
public void addSigner(
PrivateKey key,
X509Certificate cert,
String digestOID)
throws IllegalArgumentException
{
String encOID = getEncOID(key, digestOID);
signerInfs.add(new SignerInf(key, cert, digestOID, encOID, new DefaultSignedAttributeTableGenerator(), null, null));
}
开发者ID:esaito,项目名称:ExemplosDemoiselle,代码行数:19,代码来源:CMSTabeliaoSignedDataGenerator.java
示例5: generateMultiPartRsa
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的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
示例6: signBySnox
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/41767351/create-pkcs7-signature-from-file-digest">
* Create pkcs7 signature from file digest
* </a>
* <p>
* The OP's own <code>sign</code> method which has some errors. These
* errors are fixed in {@link #signWithSeparatedHashing(InputStream)}.
* </p>
*/
public byte[] signBySnox(InputStream content) throws IOException {
// testSHA1WithRSAAndAttributeTable
try {
MessageDigest md = MessageDigest.getInstance("SHA1", "BC");
List<Certificate> certList = new ArrayList<Certificate>();
CMSTypedData msg = new CMSProcessableByteArray(IOUtils.toByteArray(content));
certList.addAll(Arrays.asList(chain));
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
Attribute attr = new Attribute(CMSAttributes.messageDigest,
new DERSet(new DEROctetString(md.digest(IOUtils.toByteArray(content)))));
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
SignerInfoGeneratorBuilder builder = new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));
AlgorithmIdentifier sha1withRSA = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA");
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(chain[0].getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
gen.addSignerInfoGenerator(builder.build(
new BcRSAContentSignerBuilder(sha1withRSA,
new DefaultDigestAlgorithmIdentifierFinder().find(sha1withRSA))
.build(PrivateKeyFactory.createKey(pk.getEncoded())),
new JcaX509CertificateHolder(cert)));
gen.addCertificates(certs);
CMSSignedData s = gen.generate(new CMSAbsentContent(), false);
return new CMSSignedData(msg, s.getEncoded()).getEncoded();
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e);
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:55,代码来源:CreateSignature.java
示例7: testSHA224WithRSAParserEncryptedWithDES
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
public void testSHA224WithRSAParserEncryptedWithDES()
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs))).build("SHA224withRSA", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
MimeMultipart smm = gen.generate(msg);
SMIMESignedParser s = new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);
certs = s.getCertificates();
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(certs, s.getSignerInfos());
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:NewSMIMESignedTest.java
示例8: testWithAttributeCertificate
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator; //导入依赖的package包/类
public void testWithAttributeCertificate()
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs))).build("SHA256withRSA", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
X509AttributeCertificateHolder attrCert = CMSTestUtil.getAttributeCertificate();
List attrCertList = new ArrayList();
attrCertList.add(attrCert);
Store store = new CollectionStore(attrCertList);
gen.addAttributeCertificates(store);
SMIMESigned s = new SMIMESigned(gen.generateEncapsulated(msg));
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificates(), s.getSignerInfos());
Store attrCerts = s.getAttributeCertificates();
assertTrue(attrCerts.getMatches(null).contains(attrCert));
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:39,代码来源:NewSMIMESignedTest.java
注:本文中的org.bouncycastle.cms.DefaultSignedAttributeTableGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论