Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Unable to encrypt using AES 256bits

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to encrypt using AES 256bits

    Hi,

    i trying to write a method to encrypt data using AES 256 but everytimes when i trying to pass the 256bits key to the java cipher it throw Invalid Key Exception, it works only for 128bits key. Below is part of my code

    KeyGenerator keygen = KeyGenerator.getInstance("AES");
    keygen.init(256);
    SecretKey secret = keygen.generateKey();
    System.out.println(secret.getEncoded().length);
    SecretKeySpec spec = new SecretKeySpec(secret.getEncoded(),"AES");
     
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, spec);

    It show that the key is 32 bytes which is 256bits but when i put the key into cipher.init() it throw invalid key error. I think it is the transformation "AES" which i pass to cipher.getinstance() is wrong. Anyone know what is the correct transformation for 256bits AES encryption?

    Thanks.


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unable to encrypt using AES 256bits

    Hi,

    The problem is resolved. To use AES 256bits, you need to download the unlimited strength JCE policy files from Sun and install it. Replace the 2 jar files in your jdk folder.

    https://cds.sun.com/is-bin/INTERSHOP...-CDS_Developer

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Unable to encrypt using AES 256bits

    Congratulations on solving your issue. I have marked this thread as solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. How do i encrypt my password at command line
    By AHOT in forum Java Theory & Questions
    Replies: 5
    Last Post: October 13th, 2010, 03:13 PM
  2. Need Help for encrypt/decrypt.
    By superdhebz in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 17th, 2010, 12:17 PM
  3. unable to get the o/p for xml file
    By javaking in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: April 11th, 2010, 11:59 PM
  4. unable to run log code
    By javaking in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2010, 11:49 PM
  5. Unable to sendViaPost to url
    By mousumi in forum Java Networking
    Replies: 2
    Last Post: January 28th, 2010, 04:52 AM