public function setKey($key, $iv = null)
    {
        if (!is_string($key)) {
            throw new Horde_Crypt_Blowfish_Exception('Encryption key must be a string.');
        }

        $len = strlen($key);
        if (($len > self::MAXKEYSIZE) || ($len == 0)) {
            throw new Horde_Crypt_Blowfish_Exception(sprintf('Encryption key must be less than %d characters (bytes) and non-zero. Supplied key length: %d', self::MAXKEYSIZE, $len));
        }

        $this->_crypt->key = $key;

        switch ($this->_crypt->cipher) {
        case 'cbc':
            if (is_null($iv)) {
                if (is_null($this->iv)) {
                    $this->_crypt->setIv();
                }
            } else {
                $iv = substr($iv, 0, self::IV_LENGTH);
                if (($len = strlen($iv)) < self::IV_LENGTH) {
                    $iv .= str_repeat(chr(0), self::IV_LENGTH - $len);
                }
                $this->_crypt->setIv($iv);
            }
            break;

        case 'ecb':
            $this->iv = false;
            break;
        }
    }