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

AES cipher.init method cann't check key size correctly

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beagle
    • CPU:
      sparc
    • OS:
      solaris_8
    • Verification:
      Verified

      Description

      The AES cipher can not accept the key size correctly.

      1: put the sunaes.jar file in the $JAVA_HOME/lib/ext.
      2: add the line "security.provider.6=com.sun.advcrypto.provider.SunAES" in the java.security file in $JAVA_HOME/lib/security directory.
      3: complie the test file(seems compiler find the correct jar file)
      4: execute it. you will find a exception.

      the following program demonstrates this:


      import java.io.PrintStream;
      import java.security.*;
      import java.security.spec.*;

      import javax.crypto.*;
      import javax.crypto.spec.*;
      import java.security.Provider;
      import com.sun.advcrypto.provider.SunAES;

      public class test {

           public static void main( String argv[] ) {
           try{
               String algorithm = "AES";
           String mode = "ECb";
          String padding = "NoPadding";
           int keyStrength=128;
           AlgorithmParameterSpec aps = null;
       
        Cipher ci = Cipher.getInstance( algorithm, "SunAES" );
       
           KeyGenerator kg = KeyGenerator.getInstance( algorithm, "SunAES" );
           kg.init(keyStrength);
           SecretKey key = kg.generateKey();

           ci.init( Cipher.ENCRYPT_MODE, key, aps);
          
           System.out.println("PASSED");
           }catch(Exception ex){
           System.out.println("FAILED");
           ex.printStackTrace();
          
           }
           }

      }

      lwang:/home/lw129730( 211 )%java test
      FAILED
      java.security.InvalidKeyException
              at cryptix.jce.provider.cipher.Rijndael.engineGetKeySize(DashoA6275)
              at javax.crypto.Cipher.init(DashoA6275)
              at test.main(test.java:28)

        Attachments

          Activity

            People

            Assignee:
            valeriep Valerie Peng
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: