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

AES cipher cann't generate required IV in encrypt mode

    XMLWordPrintable

Details

    • beagle
    • sparc
    • solaris_8
    • Verified

    Description

      If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption. But the AES cipher can not. The following program demonstrates this.


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

      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{
          
      byte[] iv = null;
               String algorithm = "AES";
           String mode = "CBC";
          String padding = "NoPadding";
        int keyStrength=128;
        AlgorithmParameterSpec aps = null;
       
        Cipher ci = Cipher.getInstance( algorithm + "/" + mode + "/" + padding, "SunAES" );
       
        KeyGenerator kg = KeyGenerator.getInstance( algorithm, "SunAES" );
           kg.init(keyStrength);
           SecretKey key = kg.generateKey();

           ci.init( Cipher.ENCRYPT_MODE, key, aps);

           }catch(Exception ex){
           System.out.println("FAILED");
           ex.printStackTrace();
          
           }
           }
      }


      lwang:/home/lw129730/AES/testcode/test( 172 )%java test
      FAILED
      java.security.InvalidAlgorithmParameterException: Wrong parameter type: IV expected
              at cryptix.jce.provider.cipher.SunAES_j.b(DashoA6275)
              at cryptix.jce.provider.cipher.SunAES_i.a(DashoA6275)
              at cryptix.jce.provider.cipher.SunAES_h.a(DashoA6275)
              at cryptix.jce.provider.cipher.BlockCipher.engineInit(DashoA6275)
              at javax.crypto.Cipher.init(DashoA6275)
              at test.main(test.java:30)

      Attachments

        Activity

          People

            valeriep Valerie Peng
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: