本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.addRecipientInfoGenerator方法的典型用法代码示例。如果您正苦于以下问题:Java SMIMEEnvelopedGenerator.addRecipientInfoGenerator方法的具体用法?Java SMIMEEnvelopedGenerator.addRecipientInfoGenerator怎么用?Java SMIMEEnvelopedGenerator.addRecipientInfoGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator
的用法示例。
在下文中一共展示了SMIMEEnvelopedGenerator.addRecipientInfoGenerator方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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);
}
}
示例8: testCapEncrypt
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public void testCapEncrypt()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
//
// create a subject key id - this has to be done the same way as
// it is done in the certificate associated with the private key
//
MessageDigest dig = MessageDigest.getInstance("SHA1", BC);
dig.update(_reciCert.getPublicKey().getEncoded());
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(dig.digest(), _reciCert.getPublicKey()).setProvider(BC));
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.RC2_CBC, 40).setProvider(BC).build());
SMIMEEnveloped m = new SMIMEEnveloped(mp);
dig.update(_reciCert.getPublicKey().getEncoded());
RecipientId recId = new KeyTransRecipientId(dig.digest());
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
verifyMessageBytes(msg, res);
}
示例9: testSubKeyId
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public void testSubKeyId()
throws Exception
{
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
//
// create a subject key id - this has to be done the same way as
// it is done in the certificate associated with the private key
//
MessageDigest dig = MessageDigest.getInstance("SHA1", BC);
dig.update(SubjectPublicKeyInfo.getInstance(_reciCert.getPublicKey().getEncoded()).getPublicKeyData().getBytes());
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(dig.digest(), _reciCert.getPublicKey()).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());
SMIMEEnveloped m = new SMIMEEnveloped(mp);
dig.update(SubjectPublicKeyInfo.getInstance(_reciCert.getPublicKey().getEncoded()).getPublicKeyData().getBytes());
RecipientId recId = new KeyTransRecipientId(dig.digest());
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
verifyMessageBytes(msg, res);
}
示例10: testTwoRecipients
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public void testTwoRecipients()
throws Exception
{
MimeBodyPart _msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert2).setProvider(BC));
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.RC2_CBC, 40).setProvider(BC).build());
SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp);
RecipientId recId = getRecipientId(_reciCert2);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
FileBackedMimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP2.getPrivate()).setProvider(BC)));
verifyMessageBytes(_msg, res);
m = new SMIMEEnvelopedParser(mp);
res.dispose();
recId = getRecipientId(_reciCert);
recipients = m.getRecipientInfos();
recipient = recipients.get(recId);
res = SMIMEUtil.toMimeBodyPart(recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
verifyMessageBytes(_msg, res);
res.dispose();
}