Java - Why I can't enumerate certificates in a KeyStore by using their alias? -
keystore keystore_client = keystore.getinstance("pkcs12"); try(inputstream keyinput = new fileinputstream("2.pfx")){ keystore_client.load(keyinput, null); } enumeration<string> e = keystore_client.aliases(); while(e.hasmoreelements()){ string alias = e.nextelement(); if(keystore_client.getcertificate(alias)==null) throw new runtimeexception("cannot certificate"); }
when run code, exception: "cannot certificate".
how can extract certificates pkcs12 file?
edit:
pfx file created openssl.
$ openssl pkcs12 -export -out 2.pfx -in server.crt -inkey server.key $ keytool -list -keystore 2.pfx enter keystore password: ***************** warning warning warning ***************** * integrity of information stored in keystore * * has not been verified! in order verify integrity, * * must provide keystore password. * ***************** warning warning warning ***************** keystore type: jks keystore provider: sun keystore contains 1 entry 1, may 9, 2016, privatekeyentry,
the reason why not getting certificate because not providing password. take closer @ warning getting:
***************** warning warning warning ***************** * integrity of information stored in keystore * * has not been verified! in order verify integrity, * * must provide keystore password. * ***************** warning warning warning *****************
if junit tests on code , try keystores password , without password see ones need password let certificates via code, , of course provided input correct password.
another thing you'll see if try extract command line is:
***************** warning warning warning ***************** * integrity of information stored in keystore * * has not been verified! in order verify integrity, * * must provide keystore password. * ***************** warning warning warning ***************** keytool error: java.lang.exception: alias <1> has no certificate
Comments
Post a Comment