Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6302061

Doc bug: setEntry(String, KeyStore.Entry, char[]) does not exist

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • security-libs
    • None
    • beta
    • x86
    • windows_xp
    • Verified

      This is from Keystore javadoc:
      ----------------
       Before a keystore can be accessed, it must be loaded.

          KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

          // get user password and file input stream
          char[] password = getPassword();
          java.io.FileInputStream fis =
              new java.io.FileInputStream("keyStoreName");
          ks.load(fis, password);
          fis.close();
       

      To create an empty keystore using the above load method, pass null as the InputStream argument.

      Once the keystore has been loaded, it is possible to read existing entries from the keystore, or to write new entries into the keystore:

          // get my private key
          KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
              ks.getEntry("privateKeyAlias", password);
          PrivateKey myPrivateKey = pkEntry.getPrivateKey();

          // save my secret key
          javax.crypto.SecretKey mySecretKey;
          KeyStore.SecretKeyEntry skEntry =
              new KeyStore.SecretKeyEntry(mySecretKey);
          ks.setEntry("secretKeyAlias", skEntry, password);

          // store away the keystore
          java.io.FileOutputStream fos =
              new java.io.FileOutputStream("newKeyStoreName");
          ks.store(fos, password);
          fos.close();
      -----------------

      In the example code, there is a call to setEntry(String, KeyStore.Entry, char[]), which does not exist.

            weijun Weijun Wang
            bsitu Bill Situ
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: