Horde_Crypt_Pgp::getSignersKeyID PHP Method

getSignersKeyID() public method

Returns the key ID of the key used to sign a block of PGP data.
public getSignersKeyID ( string $text ) : string
$text string The PGP signed text block.
return string The key ID of the key used to sign $text, or null if not found.
    public function getSignersKeyID($text)
    {
        $this->_initDrivers();
        foreach ($this->_backends as $val) {
            try {
                return $val->getSignersKeyId($text);
            } catch (Horde_Crypt_Exception $e) {
            }
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * Verifies a signed message with a given public key.
  *
  * @param string $text       The text to verify.
  * @param string $address    E-mail address of public key.
  * @param string $signature  A PGP signature block.
  * @param string $charset    Charset to use.
  *
  * @return stdClass  See Horde_Crypt_Pgp::decrypt().
  * @throws Horde_Crypt_Exception
  */
 public function verifySignature($text, $address, $signature = '', $charset = null)
 {
     if (!empty($signature)) {
         $packet_info = $this->_pgp->pgpPacketInformation($signature);
         if (isset($packet_info['keyid'])) {
             $keyid = $packet_info['keyid'];
         }
     }
     if (!isset($keyid)) {
         $keyid = $this->_pgp->getSignersKeyID($text);
     }
     /* Get key ID of key. */
     $public_key = $this->getPublicKey($address, array('keyid' => $keyid));
     if (empty($signature)) {
         $options = array('type' => 'signature');
     } else {
         $options = array('type' => 'detached-signature', 'signature' => $signature);
     }
     $options['pubkey'] = $public_key;
     if (!empty($charset)) {
         $options['charset'] = $charset;
     }
     return $this->_pgp->decrypt($text, $options);
 }