code: public static KeyPair generateKeyPair(String algorithm, int keySize) {
          KeyPairGenerator keyPairGenerator;
          try {
              keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
          } catch (NoSuchAlgorithmException e) {
              throw new IllegalArgumentException(e);
          }
          keyPairGenerator.initialize(keySize);
          return keyPairGenerator.generateKeyPair();
      }
docs: Generate a {@link KeyPair} for the given assymmetric algorithm and keysize
  
  Example: CipherUtils.generateKeyPair("RSA", 2048)