According to my understanding of documentation there should be possbile to access Microsoft Windows KeyStore by service "Windows-MY"
.
When I load PrivateKey from keyStore I get null
for privateKey.getEncoded().
How can I properly access PrivateKey from Windows keystore?
Trying to access it with:
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null);
PrivateKey privateKey = (PrivateKey) ks.getKey("myKeyAlias", null);
System.out.println("privateKey:" + privateKey));
System.out.println("getEncoded:" + privateKey.getEncoded());
Output I'm getting:
privateKey:RSAPrivateKey [size=2048 bits, type=Exchange, container=myKeyAlias]
getEncoded:null
Using JRE 1.8 and tested with Win7 and 8.1
The MSCAPI does not seem to support private key export.
First of all the Key.getEncoded()
javadoc specifies:
Returns the key in its primary encoding format, or null if this key does not support encoding.
And if you look at the source code of the Java crypto provider for MSCAPI, the getEncoded()
method actually returns null
in all cases.