code: public static KeyPairGenerator getInstance(String algorithm)
              throws NoSuchAlgorithmException {
          List<Service> list =
                  GetInstance.getServices("KeyPairGenerator", algorithm);
          Iterator<Service> t = list.iterator();
          if (t.hasNext() == false) {
              throw new NoSuchAlgorithmException
                  (algorithm + " KeyPairGenerator not available");
          }
          // find a working Spi or KeyPairGenerator subclass
          NoSuchAlgorithmException failure = null;
          do {
              Service s = t.next();
              try {
                  Instance instance =
                      GetInstance.getInstance(s, KeyPairGeneratorSpi.class);
                  if (instance.impl instanceof KeyPairGenerator) {
                      return getInstance(instance, algorithm);
                  } else {
                      return new Delegate(instance, t, algorithm);
                  }
              } catch (NoSuchAlgorithmException e) {
                  if (failure == null) {
                      failure = e;
                  }
              }
          } while (t.hasNext());
          throw failure;
      }
docs: Returns a KeyPairGenerator object that generates public/private
  key pairs for the specified algorithm.
  
  <p> This method traverses the list of registered security Providers,
  starting with the most preferred Provider.
  A new KeyPairGenerator object encapsulating the
  KeyPairGeneratorSpi implementation from the first
  Provider that supports the specified algorithm is returned.
  
  <p> Note that the list of registered providers may be retrieved via
  the {@link Security#getProviders() Security.getProviders()} method.
  
  @param algorithm the standard string name of the algorithm.
  See the KeyPairGenerator section in the <a href=
  "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#KeyPairGenerator">
  Java Cryptography Architecture Standard Algorithm Name Documentation</a>
  for information about standard algorithm names.
  
  @return the new KeyPairGenerator object.
  
  @exception NoSuchAlgorithmException if no Provider supports a
  KeyPairGeneratorSpi implementation for the
  specified algorithm.
  
  @see Provider