8286423: Destroy password protection in the example code in KeyStore

Reviewed-by: weijun
This commit is contained in:
Xue-Lei Andrew Fan 2022-05-12 13:51:47 +00:00
parent e4439ca32a
commit 1904e9d280

View file

@ -143,9 +143,9 @@ import sun.security.util.Debug;
* to read existing entries from the keystore, or to write new entries * to read existing entries from the keystore, or to write new entries
* into the keystore: * into the keystore:
* <pre> * <pre>
* KeyStore.ProtectionParameter protParam = * KeyStore.PasswordProtection protParam =
* new KeyStore.PasswordProtection(password); * new KeyStore.PasswordProtection(password);
* * try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
* // get my private key * // get my private key
* KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) * KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
* ks.getEntry("privateKeyAlias", protParam); * ks.getEntry("privateKeyAlias", protParam);
@ -158,8 +158,9 @@ import sun.security.util.Debug;
* ks.setEntry("secretKeyAlias", skEntry, protParam); * ks.setEntry("secretKeyAlias", skEntry, protParam);
* *
* // store away the keystore * // store away the keystore
* try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
* ks.store(fos, password); * ks.store(fos, password);
* } finally {
* protParam.destroy();
* } * }
* </pre> * </pre>
* *