My experience with this was that when I had this in every execution it was fine using the provider as a string like this
Security.addProvider(new BounctCastleProvider());
new JcaPEMKeyConverter().setProvider("BC");
But when I optimized and put the following in the constructor:
if(bounctCastleProvider == null) {
bounctCastleProvider = new BouncyCastleProvider();
}
if(Security.getProvider(bouncyCastleProvider.getName()) == null) {
Security.addProvider(bouncyCastleProvider);
}
Then I had to use provider like this or I would get the above error:
new JcaPEMKeyConverter().setProvider(bouncyCastleProvider);
I am using bcpkix-jdk15on version 1.65