-
Bug
-
Resolution: Fixed
-
P3
-
unknown
-
beagle
-
sparc
-
solaris_8
-
Verified
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)
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)