Wednesday 16 July 2014

InvalidKeyException

This is the exception for invalid Keys (invalid encoding, wrong length, uninitialized, etc).

import java.security.InvalidKeyException;
import javax.crypto.spec.DESKeySpec;

public class InvalidkeyExceptionEx {
    public static void main(String args[]) throws InvalidKeyException{
        byte key[] = {1,2,3};
        DESKeySpec spec = new DESKeySpec(key);
    }
}

When you tries to run the program, below error thrown.

Exception in thread "main" java.security.InvalidKeyException: Wrong key size
 at javax.crypto.spec.DESKeySpec.<init>(DESKeySpec.java:155)
 at javax.crypto.spec.DESKeySpec.<init>(DESKeySpec.java:131)
 at InvalidkeyExceptionEx.main(InvalidkeyExceptionEx.java:7)
Java Result: 1



                                                             Home

No comments:

Post a Comment