ParagonIE\GPGMailer\GPGMailer::import PHP Method

import() public method

Import a public key, return the fingerprint
public import ( string $gpgKey ) : string
$gpgKey string An ASCII armored public key
return string The GPG fingerprint for this key
    public function import(string $gpgKey) : string
    {
        try {
            $gnupg = new \Crypt_GPG($this->options);
            $data = $gnupg->importKey($gpgKey);
            return $data['fingerprint'];
        } catch (\Crypt_GPG_NoDataException $ex) {
            return '';
        } catch (\Crypt_GPG_Exception $ex) {
            return '';
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @covers GPGMailer::sign()
  * @covers GPGMailer::verify()
  */
 public function testSignedMessage()
 {
     // First, create a Zend\Mail message as usual:
     $message = new Message();
     $message->addTo('*****@*****.**', 'GPGMailer Test Email');
     $message->setBody('Cleartext for now. We are going to sign this.');
     $privateKey = file_get_contents(__DIR__ . '/private.key');
     // Instantiate GPGMailer:
     $gpgMailer = new GPGMailer(new File(), ['homedir' => '~'], $privateKey);
     $publicKey = file_get_contents(__DIR__ . '/public.key');
     $signature = $gpgMailer->sign($message);
     $this->assertTrue(\strpos($signature->getBodyText(), '-----BEGIN PGP SIGNATURE-----') !== false);
     $fingerprint = $gpgMailer->import($publicKey);
     $this->assertTrue($gpgMailer->verify($signature, $fingerprint));
 }