Exemple #1
0
 /**
  * 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.
  *
  * Do note that when a new key is loaded the index will be cleared.
  *
  * Returns true on success, false on failure
  *
  * @see getPublicKey()
  * @access public
  * @param String $key
  * @param Integer $type optional
  * @return Boolean
  */
 function setPublicKey($key, $type = RSA_PUBLIC_FORMAT_PKCS1)
 {
     $components = $this->_parseKey($key, $type);
     if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
         user_error('Trying to load a public key?  Use loadKey() instead.  It\'s called loadKey() and not loadPrivateKey() for a reason.', E_USER_NOTICE);
         return false;
     }
     $this->publicExponent = $components['publicExponent'];
     return true;
 }