title: Bouncy Castle, NoSuchMethodError (org.bouncycastle.asn1.ASN1Integer)
body: <p>I'm totally new to crypto/certs and trying to generate a certificate using the Bouncy Castle libraries.  Looking at some of their sample code, this is what I have so far:</p>
  
  <pre><code>package crypto;
  
  import org.bouncycastle.asn1.x500.X500Name;
  import org.bouncycastle.asn1.x509.BasicConstraints;
  import org.bouncycastle.asn1.x509.Extension;
  import org.bouncycastle.asn1.x509.KeyUsage;
  import org.bouncycastle.cert.X509v1CertificateBuilder;
  import org.bouncycastle.cert.X509v3CertificateBuilder;
  import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
  import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
  import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
  import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
  import org.bouncycastle.jce.provider.BouncyCastleProvider;
  import org.bouncycastle.operator.ContentSigner;
  import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
  
  import javax.security.auth.x500.X500Principal;
  import java.io.IOException;
  import java.io.InputStream;
  import java.math.BigInteger;
  import java.security.*;
  import java.security.cert.X509Certificate;
  import java.util.Date;
  import java.util.Properties;
  
  
  public class App {
  
      private static final int VALIDITY_PERIOD = 7 * 24 * 60 * 60 * 1000; // one week
  
      public static void main (String[] args) throws Exception {
          Security.addProvider(new BouncyCastleProvider());
          KeyPair keyPair = generateRSAKeyPair();
          X509Certificate rootCert = buildRootCert(keyPair);
          buildEndEntityCert(keyPair.getPublic(), keyPair.getPrivate(), rootCert);
      }
  
      /**
       * Create a random 2048 bit RSA key pair
       */
      public static KeyPair generateRSAKeyPair() throws Exception {
          KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
          kpGen.initialize(2048, new SecureRandom());
  
          return kpGen.generateKeyPair();
      }
  
      /**
       * Build a sample V1 certificate to use as a CA root certificate
       */
      public static X509Certificate buildRootCert(KeyPair keyPair)
              throws Exception
      {
          X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(
                  new X500Name("CN=Test Root Certificate"),
                  BigInteger.valueOf(1),
                  new Date(System.currentTimeMillis()),
                  new Date(System.currentTimeMillis() + VALIDITY_PERIOD),
                  new X500Name("CN=Test Root Certificate"),
                  keyPair.getPublic());
  
          ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA").setProvider("BC").build(keyPair.getPrivate());
  
          return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certBldr.build(signer));
      }
  
      /**
       * Build a sample V3 certificate to use as an end entity certificate
       */
      public static X509Certificate buildEndEntityCert(PublicKey entityKey, PrivateKey caKey, X509Certificate caCert)
              throws Exception
      {
  
          X509v3CertificateBuilder certBldr = new JcaX509v3CertificateBuilder(
                  caCert.getSubjectX500Principal(),
                  BigInteger.valueOf(1),
                  new Date(System.currentTimeMillis()),
                  new Date(System.currentTimeMillis() + VALIDITY_PERIOD),
                  new X500Principal("CN=Test End Entity Certificate"),
                  entityKey);
  
          JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
  
          certBldr.addExtension(Extension.authorityKeyIdentifier, false, extUtils.createAuthorityKeyIdentifier(caCert))
                  .addExtension(Extension.subjectKeyIdentifier, false, extUtils.createSubjectKeyIdentifier(entityKey))
                  .addExtension(Extension.basicConstraints, true, new BasicConstraints(false))
                  .addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
  
          ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(caKey);
  
          return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certBldr.build(signer));
      }
  }
  </code></pre>
  
  <p>My pom has the various Bouncy Castle libs and latest itext:</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcprov-jdk15on&lt;/artifactId&gt;
              &lt;version&gt;1.56&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcpkix-jdk15on&lt;/artifactId&gt;
              &lt;version&gt;1.47&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcmail-jdk15&lt;/artifactId&gt;
              &lt;version&gt;1.46&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcprov-ext-jdk15on&lt;/artifactId&gt;
              &lt;version&gt;1.55&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcpg-jdk15on&lt;/artifactId&gt;
              &lt;version&gt;1.56&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
              &lt;artifactId&gt;bcprov-debug-jdk15on&lt;/artifactId&gt;
              &lt;version&gt;1.55&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-configuration&lt;/groupId&gt;
              &lt;artifactId&gt;commons-configuration&lt;/artifactId&gt;
              &lt;version&gt;1.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
              &lt;artifactId&gt;itextpdf&lt;/artifactId&gt;
              &lt;version&gt;5.5.11&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>But I'm getting this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodError: org.bouncycastle.asn1.ASN1Integer.&lt;init&gt;(I)V
      at org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder.createPSSParams(Unknown Source)
      at org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder.&lt;clinit&gt;(Unknown Source)
      at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.&lt;init&gt;(Unknown Source)
      at crypto.App.buildRootCert(App.java:62)
      at crypto.App.main(App.java:34)
  
  Process finished with exit code 1
  </code></pre>
  
  <p>Does anyone know why?  </p>