private function digest_signature($method) {
        if (!$this->_digestchallenge) {
            $this->digest_auth();
        }

        $signature = array();
        $signature['username'] = '"' . $this->_user . '"';
        $signature['realm'] = '"' . $this->_digestchallenge['realm'] . '"';
        $signature['nonce'] = '"' . $this->_digestchallenge['nonce'] . '"';
        $signature['uri'] = '"' . $this->_path . '"';

        if (isset($this->_digestchallenge['algorithm']) && $this->_digestchallenge['algorithm'] != 'MD5') {
            $this->_error_log('Algorithm other than MD5 are not supported');
            return false;
        }

        $a1 = $this->_user . ':' . $this->_digestchallenge['realm'] . ':' . $this->_pass;
        $a2 = $method . ':' . $this->_path;

        if (!isset($this->_digestchallenge['qop'])) {
            $signature['response'] = '"' . md5(md5($a1) . ':' . $this->_digestchallenge['nonce'] . ':' . md5($a2)) . '"';
        } else {
            // Assume QOP is auth
            if (empty($this->_cnonce)) {
                $this->_cnonce = random_string();
                $this->_nc = 0;
            }
            $this->_nc++;
            $nc = sprintf('%08d', $this->_nc);
            $signature['cnonce'] = '"' . $this->_cnonce . '"';
            $signature['nc'] = '"' . $nc . '"';
            $signature['qop'] = '"' . $this->_digestchallenge['qop'] . '"';
            $signature['response'] = '"' . md5(md5($a1) . ':' . $this->_digestchallenge['nonce'] . ':' .
                    $nc . ':' . $this->_cnonce . ':' . $this->_digestchallenge['qop'] . ':' . md5($a2)) . '"';
        }

        $response = array();
        foreach ($signature as $key => $value) {
            $response[] = "$key=$value";
        }
        return 'Authorization: Digest ' . implode(', ', $response);
    }