Search code examples
javawindowsjavafxkeystorejpackage

Can not open Windows-MY keystore when using jpackage


Problem:

Using JPackage to create an executable for Windows does not work with KeyStore. It returns an error.

Code:

KeyStore.getInstance("Windows-MY");

will throw exception:

java.security.KeyStoreException: Windows-MY not found
  at java.base/java.security.KeyStore.getInstance(Unknown Source)
 ...
Caused by: java.security.NoSuchAlgorithmException: Windows-MY KeyStore not available
  at java.base/sun.security.jca.GetInstance.getInstance(Unknown Source) at java.base/java.security.Security.getImpl(Unknown Source)

Running the jpackage for Windows and trying to execute KeyStore.getInstance("Windows-MY"); returns the error above.

Running the application in the IDE without JPackage works fine.


Solution

  • The support for the Windows-MY keystore is part of the module jdk.crypto.mscapi. I guess this doesn't get included with your current setup through jpackage. I don't have much experience with modules, but I guess you need to add requires jdk.crypto.mscapi; to your module-info.java, or - as you mentioned in the comments - add it to the jpackage command line with --add-modules (e.g. --add-modules jdk.crypto.mscapi).