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

javax.crypto.Cipher.doFinal behavior differs depending on platform

XMLWordPrintable

        FULL PRODUCT VERSION :
        java version "1.6.0_19"
        Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
        Java HotSpot(TM) Server VM (build 16.2-b04, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        SunOS vmsbuild-01 5.10 Generic_141415-07 i86pc i386 i86pc

        A DESCRIPTION OF THE PROBLEM :
        Calling dcipher.doFinal() with an empty byte array behaves differently depending on the platform.

        On Solaris an exception is thrown: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8.

        On linux and Windows an empty array is returned.

        In 1.6 update 13 all platforms returned an empty array, in update 19 Solaris started throwing IllegalBlockSizeException. All platforms should exhibit the same behavior.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Use attached source code

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Output: doFinal returned [B@aeffdf
        ACTUAL -
        Output: doFinal threw javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public void emptyStringTest() {
        try {
              final String DES_KEY = "XXX-fill-me-in-XXX"; // Put your key here
              byte[] desKeyData = DES_KEY.getBytes();

              DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
              SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
              SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
              Cipher dcipher = Cipher.getInstance("DES");
              dcipher.init(Cipher.DECRYPT_MODE, secretKey);
              byte[] plain = new byte[0];
              byte[] utf8 = dcipher.doFinal(plain);
              System.out.println("doFinal returned " + utf8);
        } catch (Exception e) {
              System.out.println("doFinal threw " + e);
        }
        }
        ---------- END SOURCE ----------

        Release Regression From : 6u13
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

              valeriep Valerie Peng
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: