public string rspauth(string Username, string Realm, string Password, string Nonce, string Cnonce,
  string m_Authzid, string m_DigestUri, string Qop, string m_Nc)
   {
       //          HEX( KD ( HEX(H(A1)),
       //              { nonce-value, ":" nc-value, ":",
       //                cnonce-value, ":", qop-value, ":", HEX(H(A2)) }))

       //If authzid is specified, then A1 is

       //   A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
       //        ":", nonce-value, ":", cnonce-value, ":", authzid-value }

       //If authzid is not specified, then A1 is

       //   A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
       //        ":", nonce-value, ":", cnonce-value }

       //         The server receives and validates the "digest-response". The server
       //checks that the nonce-count is "00000001". If it supports subsequent
       //authentication (see section 2.2), it saves the value of the nonce and
       //the nonce-count. It sends a message formatted as follows:

       // response-auth = "rspauth" "=" response-value

       //where response-value is calculated as above, using the values sent in
       //step two, except that if qop is "auth", then A2 is

       //    A2 = { ":", digest-uri-value }

       //And if qop is "auth-int" or "auth-conf" then A2 is

       //    A2 = { ":", digest-uri-value, ":00000000000000000000000000000000" }

       byte[] H1;
       byte[] H2;
       byte[] H3;

       // byte[] temp;
       string A1;
       string A2;
       string A3;
       string p1;
       string p2;

       var sb = new StringBuilder();
       sb.Append(Username);
       sb.Append(":");
       sb.Append(Realm);
       sb.Append(":");
       sb.Append(Password);

       H1 = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));

       sb.Remove(0, sb.Length);
       sb.Append(":");
       sb.Append(Nonce);
       sb.Append(":");
       sb.Append(Cnonce);

       if (m_Authzid != null)
       {
           sb.Append(":");
           sb.Append(m_Authzid);
       }

       A1 = sb.ToString();

       byte[] bA1 = Encoding.ASCII.GetBytes(A1);
       var bH1A1 = new byte[H1.Length + bA1.Length];

       // Array.Copy(H1, bH1A1, H1.Length);
       Array.Copy(H1, 0, bH1A1, 0, H1.Length);
       Array.Copy(bA1, 0, bH1A1, H1.Length, bA1.Length);

       H1 = new MD5CryptoServiceProvider().ComputeHash(bH1A1);

       // Console.WriteLine(util.Hash.HexToString(H1));

       sb.Remove(0, sb.Length);
       sb.Append(":");
       sb.Append(m_DigestUri);
       //if (Qop.CompareTo("auth") != 0)
       //{
       //    sb.Append(":00000000000000000000000000000000");
       //}

       A2 = sb.ToString();
       //H2 = Encoding.ASCII.GetBytes(A2);
       H2 = Encoding.UTF8.GetBytes(A2);

       H2 = new MD5CryptoServiceProvider().ComputeHash(H2);

       // create p1 and p2 as the hex representation of H1 and H2
       p1 = Hash.HexToString(H1).ToLower();
       p2 = Hash.HexToString(H2).ToLower();

       sb.Remove(0, sb.Length);
       sb.Append(p1);
       sb.Append(":");
       sb.Append(Nonce);
       sb.Append(":");
       sb.Append(m_Nc);
       sb.Append(":");
       sb.Append(Cnonce);
       sb.Append(":");
       sb.Append(Qop);
       sb.Append(":");
       sb.Append(p2);

       A3 = sb.ToString();

       H3 = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(A3));

       var m_Response = Hash.HexToString(H3).ToLower();
       return m_Response;
   }

string.Format("rspauth={0}",的更多相关文章

  1. C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}等等

    int a = 12345678; //格式为sring输出//   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); / ...

  2. String.Format数字格式化输出 {0:N2} {0:D2} {0:C2

    //格式为sring输出 //   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); //   Label2.Text = ...

  3. 【转】C# String.Format数字格式化输出各种转换{0:N2} {0:D2} {0:C2}...

    ; //格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = & ...

  4. C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}...

    int a = 12345678; //格式为sring输出//   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);// ...

  5. String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转)

    String.Format数字格式化输出 {:N2} {:D2} {:C2} (转) //格式为sring输出 // Label1.Text = string.Format("asdfads ...

  6. c#字符显示转换{0:d} string.Format()

    这一篇实际和前几个月写的没什么本质上的区别.但是这篇更明确一点,学起来easy c#字符显示转换{0:d} C#:String.Format数字格式化输出 : int a = 12345678; // ...

  7. C# String.Format格式化json字符串中包含"{" "}"报错问题

    json.Append(String.Format("{\"total\":{0},\"row\":{1}}", lineCount, st ...

  8. $是对string.Format的简化

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. 如何在string.Format()方法中输出大括号

    在string.Format参数中,大括号{}是有特殊意义的符号,但是如果我们希望最终的结果中包含大括号({}),那么我们需要怎么做呢?是”\{”吗?很遗憾,运行时,会给你一个Exception的!正 ...

随机推荐

  1. style多次设置行内样式

    语法 style="font-size:32px;background-color:#aaa"

  2. 图解Git

    转载自http://marklodato.github.io/visual-git-guide/index-zh-cn.html#diff 图解Git 其他语言: Deutsch English Es ...

  3. 洛谷 P3659 [USACO17FEB]Why Did the Cow Cross the Road I G

    //神题目(题目一开始就理解错了)... 题目描述 Why did the cow cross the road? Well, one reason is that Farmer John's far ...

  4. [SoapUI] SoapUI可以做到些什么?功能有多强大?

    SoapUI. The Swiss-Army Knife of Testing. Whether you’re a tester, developer, business analyst, or ma ...

  5. octomap相关

    转载自http://blog.csdn.net/linuxarmsummary/article/details/50924947 什么是octomap? RGBD SLAM的目的有两个:估计机器人的轨 ...

  6. 谈谈Spring 注入properties文件总结

    本篇谈谈Spring 注入properties文件总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 spring提供了多种方式来注入properties文件,本文做一个 ...

  7. C++ generic tools -- from C++ Standard Library

    今晚学了一下C++标准程序库, 来简单回顾和总结一下. 1.pair 结构体 // defined in <utility> , in the std namespace namespac ...

  8. mongodb学习-创建唯一索引(在已存在的集合创建)

    如果在已存在的集合创建,可能会存在相同的值如下: 我们可以使用(2.x版本) db.users.ensureIndex({uid:1, name:1}, {unique:true, dropDups: ...

  9. InteliJ中文乱码;IDE快捷键使用

    启动服务器的时候出现如图 解决方法: 对服务器的位置进行编辑 增加如图的信息 -Dfile.encoding=UTF-8

  10. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...