title: Add signed/authenticated attributes to CMS signature using BouncyCastle
body: <p>I want to generate a simple CMS signature using bouncycastle.
  This code works!</p>
  
  <pre><code>  Security.addProvider(new BouncyCastleProvider());
    String password = "123456";
    KeyStore ks = KeyStore.getInstance("PKCS12");
    ks.load(new FileInputStream("c:/cert_123456.p12"), password.toCharArray());
    String alias = (String)ks.aliases().nextElement();
    PrivateKey key = (PrivateKey)ks.getKey(alias, password.toCharArray());
    Certificate[] chain = ks.getCertificateChain(alias);
  
    CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
  
    generator.addSigner(key, (X509Certificate)chain[0], CMSSignedDataGenerator.DIGEST_SHA1);
    ArrayList list = new ArrayList();
    for (int i = 0; i &lt; chain.length; i++) {
         list.add(chain[i]);
    }
    CertStore chainStore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(list), "BC");
    generator.addCertificatesAndCRLs(chainStore);
    CMSProcessable content = new CMSProcessableByteArray("test".getBytes());
    CMSSignedData signedData = generator.generate(content, false, "BC");
  
    byte[] pk = signedData.getEncoded();
  </code></pre>
  
  <p>But, how to add signed attributes? <br/>
  I want to remove default signed attributes and add signature-policy-identifier.<br/></p>
  
  <p>Articles are very welcome.</p>