code: public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException {
          KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
          keyPairGenerator.initialize(keySize);
          KeyPair keyPair = keyPairGenerator.genKeyPair();
          return keyPair;
      }
docs: Generate a new RSA keypair.
  
  @param keySize - the size of the key
  @return KeyPair
  @throws NoSuchAlgorithmException on failure to load RSA key generator