title: How to encrypt an email using random key with bouncy castle
body: <p>I am using bouncy-castle for achieving SMIME (Public key encryption). To send an encrypted email to multiple recipients I chose this method</p>
  
  <ol>
  <li><p>Encrypt the email with the random key</p></li>
  <li><p>Encrypt the random key with each recipients public key and set it to the MIME message.
     If there are three recipients in the email , the object will have three encrypted  random key.</p></li>
  <li><p>Recipients will identify the suitable encrypted random key, decrypt it using their private key and decrypt the content with the help of the random key.</p></li>
  </ol>
  
  <p>What bouncy-castle class should I use to encrypt a message with random string. I know  below code can be used to encrypt a msg using recipient's certificate.</p>
  
  <pre><code>/* Create the encrypter */
  SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
  encrypter.addKeyTransRecipient((X509Certificate) certChain[0]);
  
  /* Encrypt the MimeMessage*/
  MimeBodyPart encryptedPart = encrypter.generate(signedMessage,
  SMIMEEnvelopedGenerator.RC2_CBC, "BC");
  </code></pre>
  
  <p>Can some one post me the code to encrypt a MimeMessage with random key in bouncy-castle?</p>