public static byte[] generateKey(){
  byte[] keyData=new byte[KEY_LENGTH];
  secureRandom.nextBytes(keyData);
  byte[] ivData=new byte[IV_LENGTH];
  secureRandom.nextBytes(ivData);
  byte[] key=new byte[IV_LENGTH + KEY_LENGTH];
  System.arraycopy(ivData,0,key,0,IV_LENGTH);
  System.arraycopy(keyData,0,key,IV_LENGTH,KEY_LENGTH);
  return key;
}

public static byte [ ] generateKey ( ) { byte [ ] keyData = new byte [ KEY_LENGTH ] ; secureRandom . nextBytes ( keyData ) ; byte [ ] ivData = new byte [ IV_LENGTH ] ; secureRandom . nextBytes ( ivData ) ; byte [ ] key = new byte [ IV_LENGTH + KEY_LENGTH ] ; System . arraycopy ( ivData , 0 , key , 0 , IV_LENGTH ) ; System . arraycopy ( keyData , 0 , key , IV_LENGTH , KEY_LENGTH ) ; return key ; }
generates a new symmetric encryption key .
