本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator类的典型用法代码示例。如果您正苦于以下问题:Java SMIMEEnvelopedGenerator类的具体用法?Java SMIMEEnvelopedGenerator怎么用?Java SMIMEEnvelopedGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SMIMEEnvelopedGenerator类属于org.bouncycastle.mail.smime包,在下文中一共展示了SMIMEEnvelopedGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHeaders
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testHeaders()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());
assertEquals("application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data", mp.getHeader("Content-Type")[0]);
assertEquals("attachment; filename=\"smime.p7m\"", mp.getHeader("Content-Disposition")[0]);
assertEquals("S/MIME Encrypted Message", mp.getHeader("Content-Description")[0]);
}
示例2: cryptMessage
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private static MimeMultipart cryptMessage(MimeBodyPart mbp)
throws Exception
{
// Open the key store
char[] pwd = "password".toCharArray();
KeyStore ks = MailsterKeyStoreFactory.loadKeyStore("PKCS12", "clients.p12", pwd);
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient((X509Certificate) ks.getCertificate(MailsterKeyStoreFactory.DEFAULT_CERT_ALIAS));
// generate the enveloped message
MimeBodyPart envPart = gen.generate(mbp, SMIMEEnvelopedGenerator.AES256_CBC, "BC");
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(envPart);
return multipart;
}
示例3: testHeaders
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testHeaders()
throws Exception
{
MimeBodyPart _msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(_reciCert);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, SMIMEEnvelopedGenerator.DES_EDE3_CBC, "BC");
assertEquals("application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data", mp.getHeader("Content-Type")[0]);
assertEquals("attachment; filename=\"smime.p7m\"", mp.getHeader("Content-Disposition")[0]);
assertEquals("S/MIME Encrypted Message", mp.getHeader("Content-Description")[0]);
}
示例4: verifyAlgorithm
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private void verifyAlgorithm(
String algorithmOid,
MimeBodyPart msg)
throws Exception
{
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(_reciCert);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, algorithmOid, "BC");
SMIMEEnveloped m = new SMIMEEnveloped(mp);
RecipientId recId = getRecipientId(_reciCert);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(_reciKP.getPrivate(), "BC"));
verifyMessageBytes(msg, res);
}
示例5: verifyParserAlgorithm
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private void verifyParserAlgorithm(
String algorithmOid,
MimeBodyPart msg)
throws Exception
{
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(_reciCert);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, algorithmOid, "BC");
SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp);
RecipientId recId = getRecipientId(_reciCert);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(_reciKP.getPrivate(), "BC"));
verifyMessageBytes(msg, res);
}
示例6: verifyAlgorithm
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private void verifyAlgorithm(
String algorithmOid,
MimeBodyPart msg)
throws Exception
{
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(algorithmOid)).setProvider(BC).build());
SMIMEEnveloped m = new SMIMEEnveloped(mp);
RecipientId recId = getRecipientId(_reciCert);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
verifyMessageBytes(msg, res);
}
示例7: verifyParserAlgorithm
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private void verifyParserAlgorithm(
String algorithmOid,
MimeBodyPart msg)
throws Exception
{
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(algorithmOid)).setProvider(BC).build());
SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp);
RecipientId recId = getRecipientId(_reciCert);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
verifyMessageBytes(msg, res);
}
示例8: testHeaders
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
@Test
public void testHeaders()
throws Exception {
InternetHeaders ih = new InternetHeaders();
ih.addHeader("Content-Type", "application/xml");
MimeBodyPart _msg = new MimeBodyPart(ih, "<customer name=\"bill\"/>".getBytes());
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
.setProvider("BC")
.build();
RecipientInfoGenerator generator = new JceKeyTransRecipientInfoGenerator(cert);
gen.addRecipientInfoGenerator(generator);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, encryptor);
output(mp);
}
示例9: encrypt
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
/**
* Encrypts the encapsulated MIME body part.
*
* @param cert the certificate for encryption.
* @return an S/MIME message encapsulating the encrypted MIME body part.
* @throws SMimeException if unable to encrpyt the body part.
*/
public SMimeMessage encrypt(X509Certificate cert) throws SMimeException {
try {
try {
if (cert == null) {
throw new SMimeException("No certificate for encryption");
}
setDefaults();
/* Create the encrypter */
SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
encrypter.setContentTransferEncoding(getContentTransferEncoding());
// encrypter.addKeyTransRecipient(cert); // Deprecated
encrypter.addRecipientInfoGenerator(
// JceKeyTransRecipientInfoGenerator(X509Certificate,
// [org.bouncycastle.asn1.x509.AlgorithmIdentifier])
new JceKeyTransRecipientInfoGenerator(cert).setProvider(SECURITY_PROVIDER));
/* Encrypt the body part */
MimeBodyPart encryptedPart =
// encrypter.generate(bodyPart, getEncryptAlgorithm(), SECURITY_PROVIDER); // Deprecated
// encryptor.generate(MimeBodyPart, JceCMSContentEncryptorBuilder(
// org.bouncycastle.asn1.ANS1ObjectIdentifier, [int keySize])
encrypter.generate(bodyPart,
new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(getEncryptAlgorithm()))
.setProvider(SECURITY_PROVIDER).build());
return new SMimeMessage(encryptedPart, this);
}
catch (org.bouncycastle.mail.smime.SMIMEException ex) {
throw new SMimeException(ex.getMessage(), ex.getUnderlyingException());
}
}
catch (Exception e) {
throw new SMimeException("Unable to encrypt body part", e);
}
}
示例10: encrypt
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
private MimeBodyPart encrypt(MimeBodyPart bodyPart) throws Exception{
// Create Encrypter
SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
encrypter.setContentTransferEncoding("base64");
encrypter.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(partnershipDVO.getEncryptX509Certificate())
.setProvider(SECURITY_PROVIDER));
// Encrypt BodyPart
MimeBodyPart encryptedPart = encrypter.generate(bodyPart,
new JceCMSContentEncryptorBuilder(
new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.DES_EDE3_CBC))
.setProvider(SECURITY_PROVIDER).build());
return encryptedPart;
}
示例11: encrypt
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void encrypt(X509Certificate cert, String encryptAlg) throws SFRMException {
try {
/* Create the encrypter */
SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
encrypter.setContentTransferEncoding("binary");
encrypter.addRecipientInfoGenerator(
new JceKeyTransRecipientInfoGenerator(cert).setProvider(SECURITY_PROVIDER));
/* Encrypt the body part */
if (encryptAlg.equalsIgnoreCase(ALG_ENCRYPT_RC2))
this.bodyPart = encrypter.generate(bodyPart,
new JceCMSContentEncryptorBuilder(
new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.RC2_CBC))
.setProvider(SECURITY_PROVIDER).build());
else if (encryptAlg.equalsIgnoreCase(ALG_ENCRYPT_3DES))
this.bodyPart = encrypter.generate(bodyPart,
new JceCMSContentEncryptorBuilder(
new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.DES_EDE3_CBC))
.setProvider(SECURITY_PROVIDER).build());
else
throw new SFRMException("Encryption algorithm error - " + encryptAlg);
this.setIsEncrypted(true);
} catch (org.bouncycastle.mail.smime.SMIMEException ex) {
throw new SFRMException("Unable to encrypt body part", ex.getUnderlyingException());
} catch (Exception e) {
throw new SFRMException("Unable to encrypt body part", e);
}
}
示例12: testDESEDE3Encrypted
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testDESEDE3Encrypted()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
String algorithm = SMIMEEnvelopedGenerator.DES_EDE3_CBC;
verifyAlgorithm(algorithm, msg);
}
示例13: testParserDESEDE3Encrypted
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testParserDESEDE3Encrypted()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
String algorithm = SMIMEEnvelopedGenerator.DES_EDE3_CBC;
verifyParserAlgorithm(algorithm, msg);
}
示例14: testIDEAEncrypted
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testIDEAEncrypted()
throws Exception
{
if (isPresent("IDEA"))
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
String algorithm = SMIMEEnvelopedGenerator.IDEA_CBC;
verifyAlgorithm(algorithm, msg);
}
}
示例15: testRC2Encrypted
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入依赖的package包/类
public void testRC2Encrypted()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
String algorithm = SMIMEEnvelopedGenerator.RC2_CBC;
verifyAlgorithm(algorithm, msg);
}