我使用 java KeyStore
来存储用户安全信息,并使用密码锁定(加密) key 存储,并在需要时使用密码检索信息,效果很好。
但我不知道如何更改同一个 keyStore 文件的密码
我正在使用 KeyStore.load(InputStream,Password)
方法使用用户密码访问 keystore ,并使用 keyStore.store(Keystore,password)
将值写入 keystore 。
有没有办法更改keyStore文件的密码。 我已经检查了这里提供的 api 文档: http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html
最佳答案
感谢@Danail Alexiev 的工作,使用旧密码加载 KeyStore
并使用新密码覆盖相同的 keyStoreStream 将更改 keyStore 密码(使用新密码加密 keystore 内容)
这里是引用代码:
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 ( );
关于java - 如何在Java中更改KeyStore文件的密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35558458/