title: Bouncycastle: what does the subKeyID-Parameter of AddKeyTransRecipient do?
body: <p>I'm trying to asymetrically encrypt a message of arbitrary length with bouncycastle. (1.4+ with C#)</p>
  
  <p>This is the code I have right now.  It is supposed to (but doesn't) generate a CMS message where the data itself is encrypted with AES256 with a random key and the key is encrypted with the public key from <code>keyPair</code>.</p>
  
  <p><code>keyPair</code> is an RSA-Key (RsaKeyParameters)</p>
  
  <pre><code>public static byte[] Encrypt(byte[] input, AsymmetricCipherKeyPair keyPair)
  {
      CmsEnvelopedDataGenerator generator = new CmsEnvelopedDataGenerator();
  
      // those two lines are certainly wrong.
      // I have no idea what the subKeyID parameter does
      byte[] subKeyId = new byte[] {};
      generator.AddKeyTransRecipient(keyPair.Public, subKeyId);
  
      CmsProcessableByteArray cmsByteArray = new CmsProcessableByteArray(input);
      CmsEnvelopedData envelopeData = 
        generator.Generate(cmsByteArray, CmsEnvelopedDataGenerator.Aes256Cbc);
  
      return envelopeData.GetEncoded();
  }
  </code></pre>
  
  <p>What is the <code>subKeyId</code> parameter in the <code>Encrypt</code> method for and what value does it need to have?</p>