title: Bouncy Castle as provider v/s Bouncy Castle API
body: <p>I have a case where I need to encrypt some files using OpenPGP. I am using Bouncy Castle to do so.</p>
  
  <p>As I understand it Bouncy Castle encryption can be used in java in two ways:</p>
  
  <ol>
  <li><p>I add Bouncy Castle as a provider and continue to use the standard Java libraries.</p></li>
  <li><p>I use the classes specified in the Bouncy Castle library directly.</p></li>
  </ol>
  
  <p>I wanted to know the pros and cons of both the ways and which method is recommended.</p>
  
  <p>Also if I am using the second approach then why do I still have to add Bouncy Castle as a security provider. If I do not do so then I get a "No Such Provider" exception when I execute the following line:</p>
  
  <pre><code>PGPEncryptedDataGenerator encGen =
              new PGPEncryptedDataGenerator(
              new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(withIntegrityCheck).setSecureRandom(
              new SecureRandom())
              .setProvider("BC"));
  </code></pre>