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

KeyStore.setEntry(String, Entry, ProtectionParameter) throws exception when 3rd param is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 6
    • 6
    • security-libs
    • None

      The attached sample code throws exception:

      Exception in thread "main" java.security.KeyStoreException: non-null password required to create SecretKeyEntry
              at java.security.KeyStoreSpi.engineSetEntry(KeyStoreSpi.java:529)
              at java.security.KeyStore.setEntry(KeyStore.java:1285)
              at genHmacSha1.main(genHmacSha1.java:16)

      According to javadoc, the 3rd param of KeyStore.setEntry could be null.

      ------------------
      import java.io.FileOutputStream;
      import java.security.KeyStore;
      import javax.crypto.KeyGenerator;
      import javax.crypto.SecretKey;

      public class genHmacSha1 {
          
          public static void main(String[] args) throws Exception {
              KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1");
              SecretKey sk = kg.generateKey();

              KeyStore ks = KeyStore.getInstance("jceks");
              ks.load(null, null);
              KeyStore.SecretKeyEntry skEntry =new KeyStore.SecretKeyEntry(sk);
              ks.setEntry("HmacSHA1", skEntry, (KeyStore.ProtectionParameter)null);

              FileOutputStream fos = new FileOutputStream("hmacsha1.jceks");
              ks.store(fos, "password".toCharArray());
              fos.close();
          }
      }

            Unassigned Unassigned
            bsitu Bill Situ
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: