function setPublicKey($key = false, $type = false)
    {
        // if a public key has already been loaded return false
        if (!empty($this->publicExponent)) {
            return false;
        }

        if ($key === false && !empty($this->modulus)) {
            $this->publicExponent = $this->exponent;
            return true;
        }

        if ($type === false) {
            $types = array(
                self::PUBLIC_FORMAT_RAW,
                self::PUBLIC_FORMAT_PKCS1,
                self::PUBLIC_FORMAT_XML,
                self::PUBLIC_FORMAT_OPENSSH
            );
            foreach ($types as $type) {
                $components = $this->_parseKey($key, $type);
                if ($components !== false) {
                    break;
                }
            }
        } else {
            $components = $this->_parseKey($key, $type);
        }

        if ($components === false) {
            return false;
        }

        if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
            $this->modulus = $components['modulus'];
            $this->exponent = $this->publicExponent = $components['publicExponent'];
            return true;
        }

        $this->publicExponent = $components['publicExponent'];

        return true;
    }
function setPublicKey($key = false, $type = false)
    {
        // if a public key has already been loaded return false
        if (!empty($this->publicExponent)) {
            return false;
        }

        if ($key === false && !empty($this->modulus)) {
            $this->publicExponent = $this->exponent;
            return true;
        }

        if ($type === false) {
            $types = array(
                self::PUBLIC_FORMAT_RAW,
                self::PUBLIC_FORMAT_PKCS1,
                self::PUBLIC_FORMAT_XML,
                self::PUBLIC_FORMAT_OPENSSH
            );
            foreach ($types as $type) {
                $components = $this->_parseKey($key, $type);
                if ($components !== false) {
                    break;
                }
            }
        } else {
            $components = $this->_parseKey($key, $type);
        }

        if ($components === false) {
            return false;
        }

        if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
            $this->modulus = $components['modulus'];
            $this->exponent = $this->publicExponent = $components['publicExponent'];
            return true;
        }

        $this->publicExponent = $components['publicExponent'];

        return true;
    }
function setPublicKey ( $ key = false , $ type = false ) { // if a public key has already been loaded return false if ( ! empty ( $ this -> publicExponent ) ) { return false ; } if ( $ key === false && ! empty ( $ this -> modulus ) ) { $ this -> publicExponent = $ this -> exponent ; return true ; } if ( $ type === false ) { $ types = array ( self :: PUBLIC_FORMAT_RAW , self :: PUBLIC_FORMAT_PKCS1 , self :: PUBLIC_FORMAT_XML , self :: PUBLIC_FORMAT_OPENSSH ) ; foreach ( $ types as $ type ) { $ components = $ this -> _parseKey ( $ key , $ type ) ; if ( $ components !== false ) { break ; } } } else { $ components = $ this -> _parseKey ( $ key , $ type ) ; } if ( $ components === false ) { return false ; } if ( empty ( $ this -> modulus ) || ! $ this -> modulus -> equals ( $ components [ 'modulus' ] ) ) { $ this -> modulus = $ components [ 'modulus' ] ; $ this -> exponent = $ this -> publicExponent = $ components [ 'publicExponent' ] ; return true ; } $ this -> publicExponent = $ components [ 'publicExponent' ] ; return true ; }
Defines the public key

Some private key formats define the public exponent and some don't.  Those that don't define it are problematic when
used in certain contexts.  For example, in SSH-2, RSA authentication works by sending the public key along with a
message signed by the private key to the server.  The SSH-2 server looks the public key up in an index of public keys
and if it's present then proceeds to verify the signature.  Problem is, if your private key doesn't include the public
exponent this won't work unless you manually add the public exponent. phpseclib tries to guess if the key being used
is the public key but in the event that it guesses incorrectly you might still want to explicitly set the key as being
public.

Do note that when a new key is loaded the index will be cleared.

Returns true on success, false on failure

@see self::getPublicKey()
@access public
@param string $key optional
@param int $type optional
@return bool
Defines the public key