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. ssdb的高可用,源码分析

    ssdb,一个高性能的支持丰富数据结构的 NoSQL 数据库, 用于替代 Redis.——这是其官网的自我介绍. ssdb在leveldb存储库的基础上进行改造和丰富,添加了类似redis操作的接口, ...

  2. spring与mybatis五种整合方法

    1.采用数据映射器(MapperFactoryBean)的方式 不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数.  (1)Spring配置文件: <!-- 引入jdbc ...

  3. [模板]KMP字符串匹配

    洛谷P3375 注意:两次过程大致相同,故要熟读熟记,切勿搞混 可以看看其他的教程:http://www.cnblogs.com/c-cloud/p/3224788.html 本来就不太熟,若是在记不 ...

  4. js 获取ur参数 只要问号后面的那段传进url

    //获取url中的参数 function getUrlParam (pName, win) { var sUrl; if (typeof (win) == 'string') { sUrl = win ...

  5. xStream完美转换XML、JSON(转)

    xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...

  6. Tag recommendaion... 论文中的小例子,使用HOSVD算法推荐

    本文内容来自于论文:Tag recommendations based on tensor dimensioanlity reduction 在社会标签系统中,存在三元关系,用户-物品-标签.这些数据 ...

  7. 【转载】实战mysql分区(PARTITION)

    转载地址:http://lobert.iteye.com/blog/1955841 前些天拿到一个表,将近有4000w数据,没有任何索引,主键.(建这表的绝对是个人才) 这是一个日志表,记录了游戏中物 ...

  8. 编写高质量代码改善C#程序的157个建议——建议155:随生产代码一起提交单元测试代码

    建议155:随生产代码一起提交单元测试代码 首先提出一个问题:我们害怕修改代码吗?是否曾经无数次面对乱糟糟的代码,下决心进行重构,然后在一个月后的某个周一,却收到来自测试版的报告:新的版本,没有之前的 ...

  9. Promise实现简易AMD加载器

    在最新的Chrome和FF中已经 实现了Promise.有了Promise我们用数行代码即可实现一个简易AMD模式的加载器 var registry = { promises: { }, resolv ...

  10. SOAP协议初级指南 (一)

    SOAP(Simple Object Access Protocal) 技术有助于实现大量异构程序和平台之间的互操作性,从而使存在的应用能够被广泛的用户所访问.SOAP是把成熟的基于HTTP的WEB技 ...