如何更改 Java 中 KeyStore 文件的密码?
How to change Password of KeyStore File in Java?
我正在使用 java KeyStore
来存储用户安全信息并使用密码锁定(加密)密钥存储,并在需要时使用密码检索信息,工作正常。
但我不知道如何更改同一个 keyStore 文件的密码
我正在使用 KeyStore.load(InputStream,Password)
方法通过用户密码访问密钥库,并使用 keyStore.store(Keystore,password)
将值写入密钥库。
有没有办法修改keyStore文件的密码。
我已经检查了这里提供的 api 文档:
http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html
感谢@Danail Alexiev 它的工作,用旧密码加载 KeyStore
并用新密码覆盖相同的 keyStoreStream 将更改 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 KeyStore
来存储用户安全信息并使用密码锁定(加密)密钥存储,并在需要时使用密码检索信息,工作正常。
但我不知道如何更改同一个 keyStore 文件的密码
我正在使用 KeyStore.load(InputStream,Password)
方法通过用户密码访问密钥库,并使用 keyStore.store(Keystore,password)
将值写入密钥库。
有没有办法修改keyStore文件的密码。 我已经检查了这里提供的 api 文档: http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html
感谢@Danail Alexiev 它的工作,用旧密码加载 KeyStore
并用新密码覆盖相同的 keyStoreStream 将更改 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 ( );