code: public static SecretKey generateKey(String algorithm, int keySize) {
          KeyGenerator secretKeyGenerator;
          try {
              secretKeyGenerator = KeyGenerator.getInstance(algorithm);
          } catch (NoSuchAlgorithmException e) {
              throw new IllegalArgumentException(e);
          }
          secretKeyGenerator.init(keySize);
          return secretKeyGenerator.generateKey();
      }
docs: Generate a {@link SecretKey} for the given symmetric algorithm and keysize
  
  Example: CipherUtils.generateKeyPair("AES", 128)