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; }