本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.addKeyTransRecipient方法的典型用法代码示例。如果您正苦于以下问题:Java SMIMEEnvelopedGenerator.addKeyTransRecipient方法的具体用法?Java SMIMEEnvelopedGenerator.addKeyTransRecipient怎么用?Java SMIMEEnvelopedGenerator.addKeyTransRecipient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator
的用法示例。
在下文中一共展示了SMIMEEnvelopedGenerator.addKeyTransRecipient方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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]);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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.addKeyTransRecipient(_reciCert.getPublicKey(), dig.digest());
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, SMIMEEnvelopedGenerator.RC2_CBC, 40, "BC");
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(_reciKP.getPrivate(), "BC"));
verifyMessageBytes(_msg, res);
}
示例6: testQuotePrintableSigPreservation
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public void testQuotePrintableSigPreservation()
throws Exception
{
MimeMessage msg = new MimeMessage((Session)null, getClass().getResourceAsStream("qp-soft-break.eml"));
SMIMEEnvelopedGenerator encGen = new SMIMEEnvelopedGenerator();
encGen.addKeyTransRecipient(origCert);
MimeBodyPart mp = encGen.generate(msg, SMIMEEnvelopedGenerator.AES128_CBC, "BC");
SMIMEEnveloped env = new SMIMEEnveloped(mp);
RecipientInformation ri = (RecipientInformation)env.getRecipientInfos().getRecipients().iterator().next();
MimeBodyPart mm = SMIMEUtil.toMimeBodyPart(ri.getContentStream(origKP.getPrivate(), "BC"));
SMIMESigned s = new SMIMESigned((MimeMultipart)mm.getContent());
Collection c = s.getSignerInfos().getSigners();
Iterator it = c.iterator();
CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certs.getCertificates(selectorConverter.getCertSelector(signer.getSID()));
Iterator certIt = certCollection.iterator();
X509Certificate cert = (X509Certificate)certIt.next();
assertEquals(true, signer.verify(cert, "BC"));
}
((FileBackedMimeBodyPart)mm).dispose();
}
示例7: addEncryptionSettings
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
private void addEncryptionSettings() throws Exception {
URL keystoreUrl = new URL(keystoreFile);
InputStream publicKeystoreInputStream = keystoreUrl.openStream();
char[] smimePw = new String(keystorePass).toCharArray();
gen = new SMIMEEnvelopedGenerator();
Security.addProvider(new BouncyCastleProvider());
KeyStore ks = KeyStore.getInstance(PKCS_KEYSTORE_TYPE, BOUNCY_CASTLE_PROVIDER);
try {
ks.load(publicKeystoreInputStream, smimePw);
} finally {
publicKeystoreInputStream.close();
}
if ("".equals(keyAlias)) {
Enumeration aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = (String) aliases.nextElement();
if (ks.isKeyEntry(alias)) {
keyAlias = alias;
}
}
}
if ("".equals(keyAlias)) {
throw new Exception("Can't find a public key!");
}
Certificate[] chain = ks.getCertificateChain(keyAlias);
if (chain == null) {
throw new Exception("The key with alias \"" + keyAlias + "\" can't be fount in given keystore.");
}
//
// create the generator for creating an smime/encrypted message
//
gen.addKeyTransRecipient((X509Certificate)chain[0]);
}
示例8: sendMail
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
private static void sendMail(int port) throws Exception
{
// Open the key store
KeyStore ks = MailsterKeyStoreFactory.getInstance().getKeyStore();
Enumeration<String> e = ks.aliases();
String keyAlias = null;
String alias = null;
while (e.hasMoreElements())
{
alias = (String) e.nextElement();
if (ks.isKeyEntry(alias))
keyAlias = alias;
}
if (keyAlias == null)
{
System.err.println("can't find a private key!");
System.exit(0);
}
Certificate[] chain = ks.getCertificateChain(keyAlias);
// create the generator for creating an smime/encrypted message
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient((X509Certificate) chain[0]);
// Generate the encrypted bodyparts
// CHANGES FROM HERE
// create the base for our message
Properties props = new Properties();
props.setProperty("mail.smtp.host", "localhost");
props.setProperty("mail.smtp.port", String.valueOf(port));
Session session = Session.getInstance(props);
MimeMessage baseMsg = new MimeMessage(session);
MimeBodyPart bp1 = new MimeBodyPart();
bp1.setHeader("Content-Type", "text/plain");
bp1.setContent("Hello World!!!", "text/plain; charset=\"ISO-8859-1\"");
// Attach the file
MimeBodyPart bp2 = new MimeBodyPart();
FileDataSource fileAttachment = new FileDataSource(MailsterConstants.USER_DIR+"/pom.xml");
DataHandler dh = new DataHandler(fileAttachment);
bp2.setDataHandler(dh);
bp2.setFileName(fileAttachment.getName());
bp2.setHeader("Content-Type", "application/pdf");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(bp1);
multipart.addBodyPart(bp2);
MimeBodyPart finalPart = new MimeBodyPart();
finalPart.setContent(multipart);
baseMsg.setHeader("Content-Type", "multipart/signed");
baseMsg.setFrom(new InternetAddress("Ted <[email protected]>"));
baseMsg.setRecipient(Message.RecipientType.TO, new InternetAddress(
"John Doe <[email protected]>"));
baseMsg.setSubject("Test Signed Message");
baseMsg.setContent(signMessage(finalPart));
baseMsg.setSentDate(getRandomDate());
baseMsg.saveChanges();
Transport.send(baseMsg);
baseMsg.setRecipient(Message.RecipientType.TO, new InternetAddress(
"Mickael Fake <[email protected]>"));
baseMsg.setHeader("Content-Type", null);
baseMsg.setSubject("Example Encrypted Message II with very big subject line included " +
"in the header to test text wrapping method.");
baseMsg.setContent(cryptMessage(finalPart));
baseMsg.setSentDate(getRandomDate());
baseMsg.saveChanges();
Transport.send(baseMsg);
}
示例9: main
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public static void main(
String args[])
throws Exception
{
if (args.length != 3)
{
System.err.println("usage: CreateLargeEncryptedMail pkcs12Keystore password inputFile");
System.exit(0);
}
//
// Open the key store
//
KeyStore ks = KeyStore.getInstance("PKCS12", "BC");
String keyAlias = ExampleUtils.findKeyAlias(ks, args[0], args[1].toCharArray());
Certificate[] chain = ks.getCertificateChain(keyAlias);
//
// create the generator for creating an smime/encrypted message
//
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient((X509Certificate)chain[0]);
//
// 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
// version 3 only.
//
/*
MessageDigest dig = MessageDigest.getInstance("SHA1", "BC");
dig.update(cert.getPublicKey().getEncoded());
gen.addKeyTransRecipient(cert.getPublicKey(), dig.digest());
*/
//
// create the base for our message
//
MimeBodyPart msg = new MimeBodyPart();
msg.setDataHandler(new DataHandler(new FileDataSource(new File(args[2]))));
msg.setHeader("Content-Type", "application/octet-stream");
msg.setHeader("Content-Transfer-Encoding", "binary");
MimeBodyPart mp = gen.generate(msg, SMIMEEnvelopedGenerator.RC2_CBC, "BC");
//
// Get a Session object and create the mail message
//
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
Address fromUser = new InternetAddress("\"Eric H. Echidna\"<[email protected]>");
Address toUser = new InternetAddress("[email protected]");
MimeMessage body = new MimeMessage(session);
body.setFrom(fromUser);
body.setRecipient(Message.RecipientType.TO, toUser);
body.setSubject("example encrypted message");
body.setContent(mp.getContent(), mp.getContentType());
body.saveChanges();
body.writeTo(new FileOutputStream("encrypted.message"));
}
示例10: 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(_reciCert.getPublicKey().getEncoded());
gen.addKeyTransRecipient(_reciCert.getPublicKey(), dig.digest());
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, SMIMEEnvelopedGenerator.DES_EDE3_CBC, "BC");
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(_reciKP.getPrivate(), "BC"));
verifyMessageBytes(_msg, res);
}
示例11: testTwoRecipients
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator; //导入方法依赖的package包/类
public void testTwoRecipients()
throws Exception
{
MimeBodyPart _msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(_reciCert);
gen.addKeyTransRecipient(_reciCert2);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, SMIMEEnvelopedGenerator.RC2_CBC, 40, "BC");
SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp);
RecipientId recId = getRecipientId(_reciCert2);
RecipientInformationStore recipients = m.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
FileBackedMimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContentStream(_reciKP2.getPrivate(), "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(_reciKP.getPrivate(), "BC"));
verifyMessageBytes(_msg, res);
res.dispose();
}