См. также: http://tools.ietf.org/html/rfc4880#section-5.5.1.1
См. также: http://tools.ietf.org/html/rfc4880#section-5.5.2
См. также: http://tools.ietf.org/html/rfc4880#section-11.1
См. также: http://tools.ietf.org/html/rfc4880#section-12
Наследование: extends OpenPGP_Packet
Пример #1
0
 function body()
 {
     $bytes = parent::body() . chr($this->s2k_useage);
     $secret_material = NULL;
     if ($this->s2k_useage == 255 || $this->s2k_useage == 254) {
         $bytes .= chr($this->symmetric_algorithm);
         $bytes .= $this->s2k->to_bytes();
     }
     if ($this->s2k_useage > 0) {
         $bytes .= $this->encrypted_data;
     } else {
         $secret_material = '';
         foreach (self::$secret_key_fields[$this->algorithm] as $f) {
             $f = $this->key[$f];
             $secret_material .= pack('n', OpenPGP::bitlength($f));
             $secret_material .= $f;
         }
         $bytes .= $secret_material;
         // 2-octet checksum
         $chk = 0;
         for ($i = 0; $i < strlen($secret_material); $i++) {
             $chk = ($chk + ord($secret_material[$i])) % 65536;
         }
         $bytes .= pack('n', $chk);
     }
     return $bytes;
 }
Пример #2
0
 function read()
 {
     parent::read();
     // All the fields from PublicKey
     $this->s2k_useage = ord($this->read_byte());
     if ($this->s2k_useage == 255 || $this->s2k_useage == 254) {
         $this->symmetric_type = ord($this->read_byte());
         $this->s2k_type = ord($this->read_byte());
         $this->s2k_hash_algorithm = ord($this->read_byte());
         if ($this->s2k_type == 1 || $this->s2k_type == 3) {
             $this->s2k_salt = $this->read_bytes(8);
         }
         if ($this->s2k_type == 3) {
             $c = ord($this->read_byte());
             $this->s2k_count = (int) 16 + ($c & 15) << ($c >> 4) + 6;
         }
     } else {
         if ($this->s2k_useage > 0) {
             $this->symmetric_type = $this->s2k_useage;
         }
     }
     if ($this->s2k_useage > 0) {
         // TODO: IV of the same length as cipher's block size
         $this->encrypted_data = $this->input;
         // Rest of input is MPIs and checksum (encrypted)
     } else {
         $this->data = $this->input;
         // Rest of input is MPIs and checksum
         $this->key_from_data();
     }
 }