Use JNA to get Local machine Certificate

时光怂恿深爱的人放手 提交于 2019-12-08 09:23:38

问题


I'm trying to get a certificate from local machine Windows store. What a want to get is a certificate in the patth "Certificates(Local Computer) --> Personal --> Certificates".

I used this code to access certificate in the path "Certificates - Current User --> Personal --> Certificates

 NativeLibrary crypt32 = NativeLibrary.getInstance("Crypt32");
 Function functionCertOpenSystemStore = 
 crypt32.getFunction("CertOpenSystemStoreA");
 Object[] argsCertOpenSystemStore = new Object[] { 0, "MY"};
HANDLE h = (HANDLE) functionCertOpenSystemStore.invoke(HANDLE.class, argsCertOpenSystemStore);

Any idea about how to get a certificate from "Certificates(Local Computer) --> Personal --> Certificates"?

I'm trying to use JNA because I read is not posible to access local machine certificates from Java. I only thing I've got is to get "Current user" certificates using keystore like this :

KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");

Also I've tried this :

KeyStore ks = KeyStore.getInstance("Windows-ROOT", "SunMSCAPI");

Can someone give me a clue?


回答1:


Yes, you can use the wcsa utility, which will intercept calls to the Windows Crypto API and let you access the local machine credentials. This is of course a hack around the real problem, JDK-6782021, which was reported ten years ago. But it does let you access the local machine certificates in a pretty painless way!



来源:https://stackoverflow.com/questions/51193143/use-jna-to-get-local-machine-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!