JDK-6312917 : Cipher.init does not behave as described in the Javadocs
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Affected Version: 5.0u4
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-18
  • Updated: 2010-04-02
  • Resolved: 2005-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u4Resolved
Related Reports
Duplicate :  
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.

Comments
EVALUATION This is the same underlying issue as 4953555.
23-08-2005

WORK AROUND From IBM: Use two instances of a Cipher object instead of trying to use and re-initialize a single object.
18-08-2005