title: create PKCS7 with presigned data using bouncy castle
body: <p>I would like to create a detached signature in a PDF file using a PKCS7 container. The data (hash) is being signed beforehand on a different device with the private key. I want to create a PKCS7 containing the signed data along with the certificate with the public key. I can't seem to create the PKCS7 with bouncy castle without supplying the private key and having the library signing the data. This doesn't seem to work:</p>
  
  <pre><code>        InputStream inStream = new FileInputStream("1_public.pem");
          BufferedInputStream bis = new BufferedInputStream( inStream );
  
          CertificateFactory cf = CertificateFactory.getInstance("X.509");
  
          List&lt;Certificate&gt; certList = new ArrayList&lt;Certificate&gt;();
          Certificate certificate = cf.generateCertificate(bis);
          certList.add(certificate);
          Store certs = new JcaCertStore(certList);
  
          CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
          gen.addCertificates( certs );
          CMSProcessableInputStream msg = new CMSProcessableInputStream( new ByteArrayInputStream( "signedhash".getBytes() ) );
  
          CMSSignedData signedData = gen.generate(msg, false);
          byte[] pkcs7 = signedData.getEncoded() ) );
  </code></pre>