问题
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