See also: http://tools.ietf.org/html/rfc4880#section-4.1
See also: http://tools.ietf.org/html/rfc4880#section-4.3
Esempio n. 1
0
 function __construct($data = NULL, $opt = array())
 {
     parent::__construct();
     $this->data = $data;
     $this->format = $opt['format'] ? $opt['format'] : 'b';
     $this->filename = $opt['filename'] ? $opt['filename'] : 'data';
     $this->timestamp = $opt['timestamp'] ? $opt['timestamp'] : time();
 }
Esempio n. 2
0
 function __construct($sha1 = '')
 {
     parent::__construct();
     $this->data = $sha1;
 }
Esempio n. 3
0
 /**
  */
 public function decrypt($msg, $key)
 {
     $decryptor = new OpenPGP_Crypt_RSA($key->message);
     $elgamal = null;
     foreach ($msg->message as $val) {
         if ($val instanceof OpenPGP_AsymmetricSessionKeyPacket) {
             $pkey = $decryptor->key($val->keyid);
             if (!$pkey instanceof OpenPGP_PublicKeyPacket) {
                 continue;
             }
             switch ($pkey->algorithm) {
                 case 1:
                 case 2:
                     return new Horde_Pgp_Element_Message($decryptor->decrypt($msg->message));
                 case 16:
                     $elgamal = new Horde_Pgp_Crypt_Elgamal($pkey);
                     /* Put encrypted data into a packet object to take
                      * advantage of built-in MPI read methods. */
                     $edata = new OpenPGP_Packet();
                     $edata->input = $val->encrypted_data;
                     $sk_data = $elgamal->decrypt($edata->read_mpi() . $edata->read_mpi());
                     $sk = substr($sk_data, 1, strlen($sk_data) - 3);
                     /* Last 2 bytes are checksum */
                     $chk = unpack('n', substr($sk_data, -2));
                     $chk = reset($chk);
                     $sk_chk = 0;
                     for ($i = 0, $j = strlen($sk); $i < $j; ++$i) {
                         $sk_chk = ($sk_chk + ord($sk[$i])) % 65536;
                     }
                     if ($sk_chk != $chk) {
                         throw new RuntimeException();
                     }
                     return new Horde_Pgp_Element_Message(OpenPGP_Crypt_Symmetric::decryptPacket(OpenPGP_Crypt_Symmetric::getEncryptedData($msg->message), ord($sk_data[0]), $sk));
             }
         }
     }
     throw new RuntimeException();
 }