code: public PrivateKey getPrivateKey(String alias, String password) {
          Key key = getKey(alias, password);
          if (key instanceof PrivateKey) {
              return (PrivateKey) key;
          } else {
              throw new IllegalStateException(format("Key with alias '%s' was not a private key, but was: %s",
                      alias, key.getClass().getSimpleName()));
          }
      }
docs: Gets a asymmetric encryption private key from the key store
  @param alias key alias
  @param password key password
  @return the private key