danieln
danieln

Reputation: 4973

Validate KeyStore password in Java

I'm allowing the user to specify its own KeyStore in my application. I'd like to validate that KeyStore password, given by the user, is valid.
Is there a way doing that?

Upvotes: 3

Views: 1952

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44813

try loading it

FileInputStream is = new FileInputStream(file);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
/* getting the key*/
keystore.load(is, password.toCharArray());

Throws: IOException - if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException

Upvotes: 5

Related Questions