2

I am using java KeyStore to store user secure information and locking (encrypting) the key store with password and retrieving the information with password when needed, which is working fine.

But i don't know how to change the password for the same keyStore file

i am using KeyStore.load(InputStream,Password) method to accessing the keystore with user password and keyStore.store(Keystore,password) for writing the values into keyStore.

Is there any way to change the password of keyStore file. i have checked the api documentation give here : http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html

Tushar Purohit
  • 503
  • 7
  • 21

1 Answers1

5

Thanks @Danail Alexiev its works, loading the KeyStore with old password and the overwriting the same keyStoreStream with new password will change the keyStore password (encrypt the keystore content with new password)

here is the code for reffrence:

InputStream keyStoreStream = ontext.openFileInput ( filename );
KeyStore keyStore = KeyStore.getInstance ( KeyStore.getDefaultType ( ) );
keyStore.load ( keyStoreStream, oldPass );
FileOutputStream fileOutputStream = context.openFileOutput ( filename, Context.MODE_PRIVATE );
keystore.store ( fileOutputStream, newPassword );
fileOutputStream.close ( );
Tushar Purohit
  • 503
  • 7
  • 21