Expand my Community achievements bar.

SOLVED

how do I use BouncyCastle libraries in my maven project?

Avatar

Level 8

problem: My Java code cannot see BouncyCastle libraries.

----------------

situation: I have a component that needs to use BouncyCastle libraries. The other vendor has provided some Java examples on how to use their API and the examples uses BouncyCastle.I have tried using regular Java libraries (java.*) and it's not working. I'm just testing to see if the implementation requires BouncyCastle.

----------------

mvn integration with BouncyCastle:

To integrate BouncyCastle into my maven project, I changed core/pom.xml and added these lines

 

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
            <version>1.71</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk18on</artifactId>
            <version>1.71</version>
        </dependency>

 

According to this https://www.bouncycastle.org/latest_releases.html, I need to use jdk18on for Java 8+. I'm on Java11.

----------------

observations:

1. When running an "mvn clean install", mvn fetches the BouncyCastle libraries. (I previously didn't have the bouncycastle folder prior to running the mvn command. Also mvn does not produce any compilation errors)

 

  my-work-desktop-mac in repository/org/bouncycastle 
  ➜  pwd
  /Users/myuser/.m2/repository/org/bouncycastle
  my-work-desktop-mac in repository/org/bouncycastle 
  ➜  ls -al
  0755 - myuser 18 Apr 09:59 bcpkix-jdk18on
  0755 - myuser 18 Apr 09:59 bcprov-jdk18on
  0755 - myuser 18 Apr 09:59 bcutil-jdk18on
  my-work-desktop-mac in repository/org/bouncycastle 
  ➜  find . -iname "*.jar" -type f                                            
  ./bcprov-jdk18on/1.71/bcprov-jdk18on-1.71.jar
  ./bcutil-jdk18on/1.71/bcutil-jdk18on-1.71.jar
  ./bcpkix-jdk18on/1.71/bcpkix-jdk18on-1.71.jar

 

 

2. When I try to debug this code, my execution never stops at the 2nd or 3rd breakpoint after "stepping over" on the 1st breakpoint.

 

        try {
            String publicKeyAsString = "my-public-key-here";

            PEMParser pemParser = new PEMParser(new StringReader(publicKeyAsString)); //1st breakpoint

            String test=""; //2nd breakpoint

        } catch (Exception e) {
            System.out.println("error in here"); //3rd breakpoint
        }

 

 

3. I'm using IntelliJ and IntelliJ often highlights possible issues/problems in my code. Right now, it's highlighting all the import statements I have for "org.bouncycastle" and  "PEMParser" line in no2.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

Have you checked bundle from osgi console? if it is active or not?

Also check the dependencyfinder from osgi to make sure dependencies are available in AEM



Arun Patidar

View solution in original post

3 Replies

Avatar

Level 8

the page you linked mentions the 3rd party libraries are not resolving in system/console/bundles. but I'm not seeing it in my local AEM.

Also we've "imported" other 3rd party libraries like gson before and never encountered this problem.

 

Thanks

Avatar

Correct answer by
Community Advisor

Hi,

Have you checked bundle from osgi console? if it is active or not?

Also check the dependencyfinder from osgi to make sure dependencies are available in AEM



Arun Patidar