Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JcaX509CertificateConverter setcannot find the required provider no such provider BC

I don't understand why BC is not being recognized as provider in the setProvider("BC"). I have downloaded the latest bouncycastle hier http://www.bouncycastle.org/latest_releases.html imported it successfully. however when I run the following code:

X509Certificate crt=(X509Certificate)(new JcaX509CertificateConverter().setProvider("BC").getCertificate(crthold)); 

I get an exception that provider BC was not found.

does any one please has an idea on how this could be fixed? below is the error message I am getting

org.bouncycastle.cert.jcajce.JcaX509CertificateConverter$ExCertificateException: cannot find required provider:no such provider: BC
at org.bouncycastle.cert.jcajce.JcaX509CertificateConverter.getCertificate(Unknown Source)
at client.ClientService.genCert(ClientService.java:399)
like image 594
zeroday Avatar asked Nov 22 '13 12:11

zeroday


2 Answers

I just added an instance of the BouncyCastleProvider instead of BC and it worked perfectly. I am adding the answer for those who might be one day in the same situation:

X509Certificate crt=(X509Certificate)(new JcaX509CertificateConverter().setProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()).getCertificate(crthold));
like image 98
zeroday Avatar answered Oct 26 '22 01:10

zeroday


You need to install the Bouncy Castle provider in order to retrieve it by name. This can either be done via the java.security properties file, or via the following method call:

Security.addProvider(new BouncyCastleProvider());

You can then refer to this provider by BouncyCastleProvider.PROVIDER_NAME.

like image 30
augurar Avatar answered Oct 25 '22 23:10

augurar