简体   繁体   English

如何在Java中更改KeyStore文件的密码?

[英]How to change Password of KeyStore File in Java?

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. 我正在使用java KeyStore来存储用户安全信息,并使用密码锁定(加密)密钥存储,并在需要时使用密码检索信息,效果很好。

But i don't know how to change the password for the same keyStore file 但我不知道如何更改同一keyStore文件的密码

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. 我正在使用KeyStore.load(InputStream,Password)方法访问具有用户密码和keyStore.store(Keystore,password)以将值写入keyStore。

Is there any way to change the password of keyStore file. 有什么办法可以更改keyStore文件的密码。 i have checked the api documentation give here : http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html 我已经检查了此处提供的api文档: http : //docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html

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) 感谢@Danail Alexiev的工作,用旧密码加载KeyStore并用新密码覆盖相同的keyStoreStream将会更改keyStore密码(用新密码加密密钥库内容)

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 ( );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM