Ejemplo n.º 1
0
 public function send(ServerMessage\Crypt $message)
 {
     $message->prepend(ByteConverter::IntSixteenBits($message->getLength()));
     if (!socket_send($this->socket, $message, strlen($message), 0)) {
         $this->error();
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function encrypt()
 {
     if (!$this->getMessage()) {
         throw new CipherException('Lack of message. Use setMessage() first.', 1);
     }
     if (!$this->getKey()) {
         throw new CipherException('Lack of encrypt key. Use setKey() first.', 2);
     }
     $this->prepare();
     $this->addPad();
     $this->addChecksum();
     $ivec = $this->getRandom(self::DES_BLOCK_SIZE);
     $this->cipher->setIv($ivec);
     $crypt = new ServerMessage\Crypt();
     $crypt->set('');
     $length = $this->getMessage()->getLength();
     for ($i = 0; $i < $length; $i += self::DES_BLOCK_SIZE) {
         $range = $this->getMessage()->getRange($i, self::DES_BLOCK_SIZE);
         $des = $this->cipher->encrypt($range);
         $crypt->append($des);
         $this->cipher->setIv($des);
     }
     $crypt->append($ivec);
     return $crypt;
 }