title: Access Windows Local Machine Personal Keystore with Java (SunMSCAPI)
body: <p>Is there a way to access the windows <strong>local machine</strong> personal key storage with Java using <em>SunMSCAPI</em>?</p>
  
  <p>Usually, you can use either <b>WINDOWS-ROOT</b> (which is roughly the equivalent to the trusted storage in Java) or <b>WINDOWS-MY</b> (which contains the personal certificates which is roughly equivalent to the key storage in Java) to retrieve certificates from the windows certificate storage.</p>
  
  <p>This works fine for users, but even when impersonating the SYSTEM user, I was not able to retrieve the local machine's personal certificates.</p>
  
  <p>There exist <a href="https://stackoverflow.com/questions/51193143/use-jna-to-get-local-machine-certificate">some</a> questions regarding this that <a href="https://stackoverflow.com/questions/3612962/access-local-machine-certificate-store-in-java">use JNA</a> (which I would like to avoid, especially since it seems to be complicated to retrieve the private key from there).<br>
  Also, someone <a href="https://stackoverflow.com/questions/33788143/possible-to-access-localmachine-cetificates-in-my-store-using-sunmscapi">used psexec</a> to impersonate the SYSTEM user (using <em>psexec -s</em>). I also tried this, but have not been successful.<br>
  In the end, there is also an <a href="https://bugs.openjdk.java.net/browse/JDK-6782021" rel="nofollow noreferrer">open bug</a> in the Java Bug System.</p>
  
  <p>If anyone has an idea on how to retrieve certificates from the local machine personal storage in windows using Java, I would be grateful.</p>