I want to encrypt some text using AES with 256bit key but unable to achieve, at runtime it raises an Exception
Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters
When I change to 128 bit key size it works .I have JDK 7 and UnlimitedJCEPolicy is in JDK and JRE as part of JDK 7
Your code works for me under Ubuntu with JDK1.7.0_21 so I suspect that you do not actually have the 'unlimited strength' files installed in the jdk/jre that is actually being used. Make sure that you are picking up the jdk/jre that you think you are and if you are make sure you have installed the 'unlimited strength' files correctly.