本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMESignedGenerator.generate方法的典型用法代码示例。如果您正苦于以下问题:Java SMIMESignedGenerator.generate方法的具体用法?Java SMIMESignedGenerator.generate怎么用?Java SMIMESignedGenerator.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.mail.smime.SMIMESignedGenerator
的用法示例。
在下文中一共展示了SMIMESignedGenerator.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateMultiPartGost
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartGost(
MimeBodyPart msg)
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_signGostCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signGostKP.getPrivate(), _signGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
}
示例2: generateMultiPartECGost
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartECGost(
MimeBodyPart msg)
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_signEcGostCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signEcGostKP.getPrivate(), _signEcGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
}
示例3: generateMultiPartRsaPSS
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
String digest,
MimeBodyPart msg,
Date signingTime)
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();
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build(digest + "withRSAandMGF1", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
return gen.generate(msg);
}
示例4: generateMultiPartRsaPSS
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
String digestOid,
MimeBodyPart msg,
Date signingTime)
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
if (signingTime != null)
{
signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
}
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.ENCRYPTION_RSA_PSS, digestOid, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
}
示例5: generateMultiPartRsa
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeMultipart generateMultiPartRsa(
String digestOid,
MimeBodyPart msg,
Date signingTime,
Map micalgs)
throws Exception
{
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
if (signingTime != null)
{
signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
}
SMIMESignedGenerator gen = new SMIMESignedGenerator(micalgs);
gen.addSigner(_signKP.getPrivate(), _signCert, digestOid, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
}
示例6: sign
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
@PublicAtsApi
public Package sign( Package sourcePackage ) throws ActionException {
try {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());
}
KeyStore ks = getKeystore();
PrivateKey privateKey = (PrivateKey) ks.getKey(aliasOrCN, certPassword.toCharArray());
X509Certificate cer = (X509Certificate) ks.getCertificate(aliasOrCN);
/* Create the SMIMESignedGenerator */
SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
capabilities.addCapability(SMIMECapability.dES_CBC);
ASN1EncodableVector attributes = new ASN1EncodableVector();
attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(new IssuerAndSerialNumber(new X500Name( (cer).getIssuerDN()
.getName()),
cer.getSerialNumber())));
attributes.add(new SMIMECapabilitiesAttribute(capabilities));
if (signatureAlgorithm == null) {
signatureAlgorithm = SignatureAlgorithm.DSA.equals(privateKey.getAlgorithm())
? "SHA1withDSA"
: "MD5withRSA";
}
SMIMESignedGenerator signer = new SMIMESignedGenerator();
JcaSimpleSignerInfoGeneratorBuilder signerGeneratorBuilder = new JcaSimpleSignerInfoGeneratorBuilder();
signerGeneratorBuilder.setProvider(BouncyCastleProvider.PROVIDER_NAME);
signerGeneratorBuilder.setSignedAttributeGenerator(new AttributeTable(attributes));
signer.addSignerInfoGenerator(signerGeneratorBuilder.build(signatureAlgorithm, privateKey,
cer));
/* Add the list of certs to the generator */
List<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(cer);
Store<?> certs = new JcaCertStore(certList);
signer.addCertificates(certs);
/* Sign the message */
Session session = Session.getDefaultInstance(System.getProperties(), null);
MimeMultipart mm = signer.generate(getMimeMessage(sourcePackage));
MimeMessage signedMessage = new MimeMessage(session);
/* Set all original MIME headers in the signed message */
Enumeration<?> headers = getMimeMessage(sourcePackage).getAllHeaderLines();
while (headers.hasMoreElements()) {
signedMessage.addHeaderLine((String) headers.nextElement());
}
/* Set the content of the signed message */
signedMessage.setContent(mm);
signedMessage.saveChanges();
return new MimePackage(signedMessage);
} catch (Exception e) {
throw new ActionException(EXCEPTION_WHILE_SIGNING, e);
}
}
示例7: signMessage
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
private MimeBodyPart signMessage(MimeBodyPart bodyPart) throws Exception{
X509Certificate cert = partnershipDVO.getVerifyX509Certificate();
/* Create the SMIMESignedGenerator */
SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
capabilities.addCapability(SMIMECapability.dES_CBC);
ASN1EncodableVector attributes = new ASN1EncodableVector();
attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(
new IssuerAndSerialNumber(new X509Name(cert.getIssuerDN().getName()), cert.getSerialNumber()))
);
attributes.add(new SMIMECapabilitiesAttribute(capabilities));
SMIMESignedGenerator signer = new SMIMESignedGenerator();
signer.setContentTransferEncoding("base64");
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(SECURITY_PROVIDER)
.setSignedAttributeGenerator(new AttributeTable(attributes))
.build("SHA1withRSA",
keyMan.getPrivateKey(),
partnershipDVO.getVerifyX509Certificate()));
// Add the list of certs to the generator
ArrayList certList = new ArrayList();
certList.add(cert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
signer.addCertificates(new JcaCertStore(certList));
// Sign body part
MimeMultipart mm = signer.generate(bodyPart);
InternetHeaders headers = new InternetHeaders();
boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
headers.setHeader("Content-Type", isContentTypeFolded? mm.getContentType():mm.getContentType().replaceAll("\\s", " "));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mm.writeTo(baos);
MimeBodyPart signedPart = new MimeBodyPart(headers, baos.toByteArray());
return signedPart;
}
示例8: testMimeMultipartBinaryReader
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryReader()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESigned s = new SMIMESigned(mm, "binary");
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
}
示例9: testMimeMultipartBinaryReader
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryReader()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build("SHA1withRSA", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
MimeMultipart mm = gen.generate(m);
SMIMESigned s = new SMIMESigned(mm, "binary");
verifySigners(s.getCertificates(), s.getSignerInfos());
}
示例10: testMimeMultipartBinaryParser
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryParser()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build("SHA1withRSA", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
MimeMultipart mm = gen.generate(m);
SMIMESignedParser s = new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), mm, "binary");
verifySigners(s.getCertificates(), s.getSignerInfos());
}
示例11: sign
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void sign(X509Certificate cert, PrivateKey privateKey, String digestAlg) throws SFRMException {
try {
/* Create the SMIMESignedGenerator */
SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
capabilities.addCapability(SMIMECapability.dES_CBC);
SMIMESignedGenerator signer = new SMIMESignedGenerator();
signer.setContentTransferEncoding("binary");
String signerDigestAlg = "";
if (digestAlg.equalsIgnoreCase(ALG_SIGN_MD5))
signerDigestAlg = "MD5withRSA";
else if (digestAlg.equalsIgnoreCase(ALG_SIGN_SHA1))
signerDigestAlg = "SHA1withRSA";
else
throw new SFRMException("Encryption algorihtm error - " + digestAlg);
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder()
.setProvider(SECURITY_PROVIDER)
.build(signerDigestAlg, privateKey, cert));
/* Add the list of certs to the generator */
ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(cert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
// signer.addCertificatesAndCRLs(certs);
signer.addCertificates(new JcaCertStore(certList));
/* Sign the body part */
MimeMultipart mm = signer.generate(bodyPart);
InternetHeaders headers = new InternetHeaders();
headers.setHeader("Content-Type", mm.getContentType());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mm.writeTo(baos);
this.bodyPart = new MimeBodyPart(headers, baos.toByteArray());
this.setIsSigned(true);
} catch (org.bouncycastle.mail.smime.SMIMEException ex) {
throw new SFRMException("Unable to sign body part", ex.getUnderlyingException());
} catch (Exception e) {
throw new SFRMException("Unable to sign body part", e);
}
}
示例12: testMimeMultipart
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipart()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESigned s = new SMIMESigned(mm);
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(SMIMESignedGenerator.DIGEST_SHA1);
AttributeTable table = ((SignerInformation)s.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
Attribute hash = table.get(CMSAttributes.messageDigest);
assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
}
示例13: testMimeMultipartBinaryParserGetMimeContent
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipartBinaryParserGetMimeContent()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESignedParser s = new SMIMESignedParser(mm, "binary");
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
MimeMessage bp = s.getContentAsMimeMessage(Session.getDefaultInstance(new Properties()));
}
示例14: testMD5WithRSAAddSignersSHA1
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMD5WithRSAAddSignersSHA1()
throws Exception
{
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg, SMIMESignedGenerator.RFC3851_MICALGS);
SMIMESigned s = new SMIMESigned(smm);
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_MD5);
gen.addSigners(s.getSignerInfos());
gen.addCertificatesAndCRLs(certs);
smm = gen.generate(msg, "BC");
SMIMESigned newS = new SMIMESigned(gen.generate(msg, "BC"));
verifyMessageBytes(msg, newS.getContent());
verifySigners(newS.getCertificatesAndCRLs("Collection", "BC"), newS.getSignerInfos());
assertEquals("\"md5,sha-1\"", getMicAlg(smm));
}
示例15: testMimeMultipart
import org.bouncycastle.mail.smime.SMIMESignedGenerator; //导入方法依赖的package包/类
public void testMimeMultipart()
throws Exception
{
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
Store certs = new JcaCertStore(certList);
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build("SHA1withRSA", _signKP.getPrivate(), _signCert));
gen.addCertificates(certs);
MimeMultipart mm = gen.generate(m);
SMIMESigned s = new SMIMESigned(mm);
verifySigners(s.getCertificates(), s.getSignerInfos());
byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(SMIMESignedGenerator.DIGEST_SHA1);
AttributeTable table = ((SignerInformation)s.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
Attribute hash = table.get(CMSAttributes.messageDigest);
assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
}