code: private static byte[] generateKey(int size) throws SymmetricKeyException {
          if (size <= 0)
              throw new IllegalArgumentException("Size cannot be zero or less than zero.");
  
          try {
              SecureRandom secureRandom = new SecureRandom();
              KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
              keyGenerator.init(size * 8, secureRandom);
              return keyGenerator.generateKey().getEncoded();
          } catch (NoSuchAlgorithmException e) {
              throw new SymmetricKeyException(e);
          }
      }
docs: Generate an AES key of the specifies size in bytes.
  @param size Size in bytes
  @return An AES key
  @throws SymmetricKeyException