
 P. David Flammer - 2014-08-29 01:13:29 - 
In reply to message 3 from P. David FlammerLast fix. If the last chunk is less than 16 bytes, you need to right pad it with zeros; otherwise you get an unpredictable shift in the hex. Replace the encrypt function with the following to get it to work in AESCipher:
    public function encrypt($content, $password) {
        $key = $this->_generateKey($password);
        $input = str_split($this->_cipher->stringToHex($content), self::BYTE_LIMIT*2);
        $output = '';
        foreach ($input as $chunk)
          {
            if(strlen($chunk) < self::BYTE_LIMIT*2)
              {
                // Pad it on the right with zeros if it's short.
                $chunk = str_pad($chunk,self::BYTE_LIMIT*2,'0',STR_PAD_RIGHT);
              }
            $output .= $this->_cipher->encrypt($chunk, $key);
          }
        return $this->_cipher->hexToString($output);
    }