示例#1
0
        public static void digest_ha1(
            string alg,
            string user,
            string realm,
            string pass,
            string nonce,
            string cnonce,
            out string sessionkey)
        {
            Bstring bstring = new Bstring();

            bstring.concat(user);
            bstring.concat(":".tobyte());
            bstring.concat(realm.tobyte());
            bstring.concat(":".tobyte());
            bstring.concat(pass.tobyte());
            byte[] numArray = AuthDigest.md5_hash(bstring.bf, bstring.len);
            if (alg == "md5-sess")
            {
                bstring.len = 0;
                bstring.concat(numArray);
                bstring.concat(":".tobyte());
                bstring.concat(nonce.tobyte());
                bstring.concat(":".tobyte());
                bstring.concat(cnonce.tobyte());
                numArray = AuthDigest.md5_hash(bstring.bf, bstring.len);
            }
            sessionkey = clib.byte_to_hex(numArray);
        }
示例#2
0
        public static void digest_response(
            string ha1,
            string nonce,
            string ncount,
            string cnonce,
            string qop,
            string method,
            string uri,
            string hentity,
            out string response)
        {
            Bstring bstring = new Bstring();

            bstring.concat(method.tobyte());
            bstring.concat(":".tobyte());
            bstring.concat(uri.tobyte());
            if (qop == "auth-int")
            {
                bstring.concat(":".tobyte());
                bstring.concat(hentity.tobyte());
            }
            string hex = clib.byte_to_hex(AuthDigest.md5_hash(bstring.bf, bstring.len));

            bstring.len = 0;
            bstring.concat(ha1.tobyte());
            bstring.concat(":".tobyte());
            bstring.concat(nonce.tobyte());
            bstring.concat(":".tobyte());
            if (qop.Length > 0)
            {
                bstring.concat(ncount.tobyte());
                bstring.concat(":".tobyte());
                bstring.concat(cnonce.tobyte());
                bstring.concat(":".tobyte());
                bstring.concat(qop.tobyte());
                bstring.concat(":".tobyte());
            }
            bstring.concat(hex.tobyte());
            byte[] bs = AuthDigest.md5_hash(bstring.bf, bstring.len);
            response = clib.byte_to_hex(bs);
        }