Beispiel #1
0
 /**
  * Validates $signature for document $document with public key $this->_public_key
  * or $public_key and hash function $this->_hash_func or $hash_func.
  *
  * @param string $document    document, signature of which must be validated
  * @param string $signature   signature, which must be validated
  * @param object $public_key  public key (object of Crypt_RSA_Key class)
  * @param string $hash_func   hash function, which will be used during validating signature
  * @return mixed
  *         true, if signature of document is valid
  *         false, if signature of document is invalid
  *         null on error
  *
  * @access public
  */
 function validateSign($document, $signature, $public_key = null, $hash_func = null)
 {
     // check public key
     if (is_null($public_key)) {
         $public_key = $this->_public_key;
     } elseif (!Crypt_RSA_Key::isValid($public_key)) {
         $obj = PEAR::raiseError('invalid public key. It must be an object of Crypt_RSA_Key class', CRYPT_RSA_ERROR_WRONG_KEY);
         $this->pushError($obj);
         return null;
     }
     if ($public_key->getKeyType() != 'public') {
         $obj = PEAR::raiseError('validating key must be public', CRYPT_RSA_ERROR_NEED_PUB_KEY);
         $this->pushError($obj);
         return null;
     }
     // check hash_func
     if (is_null($hash_func)) {
         $hash_func = $this->_hash_func;
     }
     if (!function_exists($hash_func)) {
         $obj = PEAR::raiseError('cannot find hash function with name [' . $hash_func . ']', CRYPT_RSA_ERROR_WRONG_HASH_FUNC);
         $this->pushError($obj);
         return null;
     }
     return $hash_func($document) == $this->decrypt($signature, $public_key);
 }