java - Encrypting a byte [ ] using a AES 256 Session key -


i have session key changing every execution of program. have encrypt byte[ ] using session key (aes 256) how that.

i generating key

              key key;               securerandom rand = new securerandom();               keygenerator generator = keygenerator.getinstance("aes");               generator.init(rand);               generator.init(256);               key = generator.generatekey(); 

and using encrypt byte array

 public static byte[] encrypt(byte[] a,key skey) throws exception {   // instantiate cipher  cipher cipher = cipher.getinstance("aes");   cipher.init(cipher.encrypt_mode, skey);  byte[] encrypted =cipher.dofinal(a); cipher.init(cipher.decrypt_mode, skey); byte[] original = cipher.dofinal(encrypted); string originalstring = new string(original);  return encrypted; } 

but every time run program shows , error

       exception in thread "main" java.security.invalidkeyexception: illegal                key size or default parameters          @ javax.crypto.cipher.checkcryptoperm(cipher.java:1026)             @ javax.crypto.cipher.implinit(cipher.java:801)     @ javax.crypto.cipher.chooseprovider(cipher.java:864)     @ javax.crypto.cipher.init(cipher.java:1249)     @ javax.crypto.cipher.init(cipher.java:1186)     @ com.esign.verify.dochash.aes.encrypt(aes.java:52)     @ com.esign.verify.dochash.dochash.main(dochash.java:264) 


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -