Skip to content

Commit

Permalink
8286423: Destroy password protection in the example code in KeyStore
Browse files Browse the repository at this point in the history
Reviewed-by: weijun
  • Loading branch information
XueleiFan committed May 12, 2022
1 parent e4439ca commit 1904e9d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/java.base/share/classes/java/security/KeyStore.java
Expand Up @@ -143,23 +143,24 @@
* to read existing entries from the keystore, or to write new entries
* into the keystore:
* <pre>
* KeyStore.ProtectionParameter protParam =
* KeyStore.PasswordProtection protParam =
* new KeyStore.PasswordProtection(password);
* try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
* // get my private key
* KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
* ks.getEntry("privateKeyAlias", protParam);
* PrivateKey myPrivateKey = pkEntry.getPrivateKey();
*
* // get my private key
* KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
* ks.getEntry("privateKeyAlias", protParam);
* PrivateKey myPrivateKey = pkEntry.getPrivateKey();
*
* // save my secret key
* javax.crypto.SecretKey mySecretKey;
* KeyStore.SecretKeyEntry skEntry =
* new KeyStore.SecretKeyEntry(mySecretKey);
* ks.setEntry("secretKeyAlias", skEntry, protParam);
* // save my secret key
* javax.crypto.SecretKey mySecretKey;
* KeyStore.SecretKeyEntry skEntry =
* new KeyStore.SecretKeyEntry(mySecretKey);
* ks.setEntry("secretKeyAlias", skEntry, protParam);
*
* // store away the keystore
* try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
* // store away the keystore
* ks.store(fos, password);
* } finally {
* protParam.destroy();
* }
* </pre>
*
Expand Down

1 comment on commit 1904e9d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.