Sunday 13 July 2014

InvalidParameterException

This exception, designed for use by the JCA/JCE engine classes, is thrown when an invalid parameter is passed to a method.

import javax.crypto.KeyGenerator;
import java.security.NoSuchAlgorithmException;

public class SecretKeyEx {
    public static void main(String args[])throws NoSuchAlgorithmException{
        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        keyGen.init(10);
    }
}

When you tries to compile the above program below error thrown.

Exception in thread "main" java.security.InvalidParameterException: Wrong keysize: must be equal to 128, 192 or 256
 at com.sun.crypto.provider.AESKeyGenerator.engineInit(AESKeyGenerator.java:93)
 at javax.crypto.KeyGenerator.init(KeyGenerator.java:502)
 at javax.crypto.KeyGenerator.init(KeyGenerator.java:479)
 at SecretKeyEx.main(SecretKeyEx.java:20)
Java Result: 1



                                                             Home

No comments:

Post a Comment