code: public static KeyPair genRSAKeyPair (int bits)
      {
          try {
              KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
              kpg.initialize(bits);
              return kpg.genKeyPair();
          } catch (GeneralSecurityException gse) {
              log.warning("Failed to create key pair", gse);
          }
          return null;
      }
docs: Creates an RSA key pair.