Skip to content

Commit e3fa081

Browse files
author
gefeili
committed
Add a test for Chacha20-Poly1305 in SMIME
1 parent b0daf63 commit e3fa081

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

mail/src/test/java/org/bouncycastle/mail/smime/test/NewSMIMEAuthEnvelopedTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,43 @@ public void testCapEncrypt()
348348
SMIMETestUtil.verifyMessageBytes(msg, res);
349349
}
350350

351+
public void testChacha20Poly1305Encrypt()
352+
throws Exception
353+
{
354+
MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");
355+
356+
SMIMEAuthEnvelopedGenerator gen = new SMIMEAuthEnvelopedGenerator();
357+
358+
//
359+
// create a subject key id - this has to be done the same way as
360+
// it is done in the certificate associated with the private key
361+
//
362+
MessageDigest dig = MessageDigest.getInstance("SHA256", BC);
363+
364+
dig.update(_reciCert.getPublicKey().getEncoded());
365+
366+
gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(dig.digest(), _reciCert.getPublicKey()).setProvider(BC));
367+
368+
//
369+
// generate a MimeBodyPart object which encapsulates the content
370+
// we want encrypted.
371+
//
372+
MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.ChaCha20Poly1305).setProvider(BC).build());
373+
374+
SMIMEAuthEnveloped m = new SMIMEAuthEnveloped(mp);
375+
376+
dig.update(_reciCert.getPublicKey().getEncoded());
377+
378+
RecipientId recId = new KeyTransRecipientId(dig.digest());
379+
380+
RecipientInformationStore recipients = m.getRecipientInfos();
381+
RecipientInformation recipient = recipients.get(recId);
382+
383+
MimeBodyPart res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));
384+
385+
SMIMETestUtil.verifyMessageBytes(msg, res);
386+
}
387+
351388
public void testTwoRecipients()
352389
throws Exception
353390
{

0 commit comments

Comments
 (0)