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

Cipher.init does not behave as described in the Javadocs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0u4
    • Fix Version/s: 5.0u4
    • Component/s: security-libs
    • Labels:
      None

      Description

      Initializing a Cipher object the first time causes supportsParameter to be called as part of the chooseProvider call. If the Cipher object is re-initialized with a different key, the spi.engineInit method is called, and supportsParameter does not get called. The Javadoc claims that calling Cipher.init is the same as creating a new Instance and calling init, but this is not the current behavior.

      - Minimal source code that demonstrates the problem

                  System.out.println("Encrypting...");
                  cp.init(Cipher.ENCRYPT_MODE, pubKey);
                  cp.update(plainText);
                  byte[] cipherText = cp.doFinal();

                  System.out.println("Decrypting...");
                  cp.init(Cipher.DECRYPT_MODE, privKey);
                  cp.update(cipherText);
                  byte[] newPlainText = cp.doFinal();

      See Workaround section.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              andreas Andreas Sterbenz
              Reporter:
              dkorbel David Korbel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: