code: public final PublicKey generatePublic(KeySpec keySpec)
              throws InvalidKeySpecException {
          if (serviceIterator == null) {
              return spi.engineGeneratePublic(keySpec);
          }
          Exception failure = null;
          KeyFactorySpi mySpi = spi;
          do {
              try {
                  return mySpi.engineGeneratePublic(keySpec);
              } catch (Exception e) {
                  if (failure == null) {
                      failure = e;
                  }
                  mySpi = nextSpi(mySpi);
              }
          } while (mySpi != null);
          if (failure instanceof RuntimeException) {
              throw (RuntimeException)failure;
          }
          if (failure instanceof InvalidKeySpecException) {
              throw (InvalidKeySpecException)failure;
          }
          throw new InvalidKeySpecException
                  ("Could not generate public key", failure);
      }
docs: Generates a public key object from the provided key specification
  (key material).
  
  @param keySpec the specification (key material) of the public key.
  
  @return the public key.
  
  @exception InvalidKeySpecException if the given key specification
  is inappropriate for this key factory to produce a public key.