I have recently migrated from Java8 to Java11. The below piece of code is giving an issue:
One of my methods to load the provider looks like below:
Provider prototype = Security.getProvider("SunPKCS11");
final String providerConfig = config.getProviderConfig();
LOGGER.debug("providerConfig={}", providerConfig);
prototype.load(resourceLoader.getResource(providerConfig).getInputStream());
Security.addProvider(prototype);
LOGGER.debug("prototype={}", prototype);
return prototype;
And place where I am encountering exception in another method:
**KeyStore keyStore = KeyStore.getInstance("PKCS11", provider);**
keyStore.load(null, keyPassword.toCharArray());
I am getting below exception in the highlighted line of code:
java.security.KeyStoreException: PKCS11 not found
at java.security.KeyStore.getInstance(KeyStore.java:974) ~[?:?]
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: PKCS11 for
provider SunPKCS11
at sun.security.jca.GetInstance.getService(GetInstance.java:101) ~[?:?]
at sun.security.jca.GetInstance.getInstance(GetInstance.java:218) ~[?:?]
at java.security.Security.getImpl(Security.java:727) ~[?:?]
at java.security.KeyStore.getInstance(KeyStore.java:971) ~[?:?]
Kindly advice.