How to use SunMSCAPI in the plugin ?


Hello guys, I'm going to use the to get the Windwos' CA-Certs to verify the https connection. Because the jdk9 had move the SunMSCAPI  to the jdk.crypto.mscapi module, I add the compile arg like :

compileJava {
options.compilerArgs << "--add-modules=jdk.crypto.mscapi" << "--add-exports=jdk.crypto.mscapi/"

which works fine when compileJava. But in the runtime it come up with an ClassNotFoundException like :  

Caused by: java.lang.ClassNotFoundException: PluginClassLoader[PluginDescriptor....

Here is my code:

private void test() {
try {
KeyStore keyStore = KeyStore.getInstance("Windows-MY");
keyStore.load(null, null);
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String element = aliases.nextElement();
Certificate[] chain = keyStore.getCertificateChain(element);
} catch (Exception e) {
throw new RuntimeException(e);

Any idea how I can do this? or maybe I should just give up to verify the peer Cert?

BTW, the peer Cert is signed by our company's CA-Cert, which is not in the jdk's keyStore

评论操作 固定链接

Using which IDE version do you test your plugin so it fails in the runtime?

评论操作 固定链接

2020.2 is based on Java 8. Java 11 was introduced with 2020.3.
If you want to use JDK classes introduced in Java 9, you need to start using 2020.3 as a minimal targeted platform along with Java 11.

评论操作 固定链接

OK  thanks, I'll try to upgrade my IDE. Maybe disable this fearture when the user's IDE is under 2020.3