Programming/Java

Load the Bouncy Castle JCA provider

Jared 2017. 10. 27. 16:44

BouncyCastle is an open source Java library which implements a dazzling array of cryptographic algorithms, and where possible, they have been made available via the standard JCA provider interface.

In terms of JOSE algorithm support, BouncyCastle can handle all those that are not covered out-of-the-box in Java 7 and 8.

How do you set up the BouncyCastle JCA provider in your application?

First, add a dependency to BouncyCastle 1.56 or a newer stable version in your project. If you use Maven:


<dependency>

    <groupId>org.bouncycastle</groupId>

    <artifactId>bcprov-jdk15on</artifactId>

    <version>[1.56,)</version>

</dependency>


Then, load the BouncyCastle JCA provider and add it to the list of the available providers in your Java runtime:


import java.security.Provider;

import java.security.Security;

import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton;


Provider bc = BouncyCastleProviderSingleton.getInstance();

Security.addProvider(bc);


with 1.48

import java.security.Provider;

import java.security.Security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;


Security.addProvider(new BouncyCastleProvider());