Ejemplo n.º 1
0
 /**
  * GPG Encypts a message to the provided public key
  *
  * @param GPG_Public_Key $pk
  * @param string $plaintext
  * @return string encrypted text
  */
 function encrypt($pk, $plaintext)
 {
     // normalize the public key
     $key_id = $pk->GetKeyId();
     $key_type = $pk->GetKeyType();
     $public_key = $pk->GetPublicKey();
     $session_key = GPG_Utility::s_random($this->width, 0);
     $key_id = GPG_Utility::hex2bin($key_id);
     $cp = $this->gpg_session($key_id, $key_type, $session_key, $public_key) . $this->gpg_data($session_key, $plaintext);
     $code = base64_encode($cp);
     $code = wordwrap($code, 60, "\n", 1);
     return "-----BEGIN PGP MESSAGE-----\nVersion: VerySimple PHP-GPG v" . $this->version . "\n\n" . $code . "\n=" . base64_encode(GPG_Utility::crc24($cp)) . "\n-----END PGP MESSAGE-----\n";
 }
Ejemplo n.º 2
0
 function test_VerifyGnuPGDSAKey()
 {
     // OpenPGP Test Key
     $public_key_ascii = $this->getGnuPGDSAKey();
     $gpg = new GPG();
     $pub_key = new GPG_Public_Key($public_key_ascii);
     $this->assertEquals(PK_TYPE_ELGAMAL, $pub_key->GetKeyType(), 'OpenPGP Incorrect Key Type');
     $this->assertEquals('76D78F0500D026C4', $pub_key->GetKeyId(), 'OpenPGP Incorrect Key ID');
     $this->assertEquals('85E3 8F69 046B 44C1 EC9F B07B 76D7 8F05 00D0 26C4', $pub_key->GetFingerprint(), 'OpenPGP Incorrect Fingerprint');
 }