当前位置: 首页>>代码示例>>C#>>正文


C# System.Security.Cryptography.MD5CryptoServiceProvider.HashString方法代码示例

本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider.HashString方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.MD5CryptoServiceProvider.HashString方法的具体用法?C# System.Security.Cryptography.MD5CryptoServiceProvider.HashString怎么用?C# System.Security.Cryptography.MD5CryptoServiceProvider.HashString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.MD5CryptoServiceProvider的用法示例。


在下文中一共展示了System.Security.Cryptography.MD5CryptoServiceProvider.HashString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: test

        public void test()
        {
            base.UnderlyingClient.Connect(System.Net.IPAddress.Parse("10.0.1.51"), 5060);

            SIPRequest req = new SIPRequest();
            req.Method = "REGISTER";
            req.Path = "sip:" + mvarDomainName;
            req.Headers.Add("CSeq", "164 REGISTER");

            string nonce = GenerateNonce();
            System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

            string callID = Guid.NewGuid().ToString();

            req.Headers.Add("Call-ID", callID + "@" + System.Environment.MachineName);
            req.Headers.Add("To", "<sip:" + mvarUserName + "@asterisk.becker-family.mbn>");
            req.Headers.Add("Contact", "<sip:" + mvarUserName + "@10.0.1.103:5060>;q=1, <sip:" + mvarUserName + "@192.168.56.1:5060>;q=0.667, <sip:" + mvarUserName + "@169.254.80.80:5060>;q=0.334");
            req.Headers.Add("Allow", "INVITE,ACK,OPTIONS,BYE,CANCEL,SUBSCRIBE,NOTIFY,REFER,MESSAGE,INFO,PING,PRACK");
            req.Headers.Add("Expires", "3600");
            req.Headers.Add("Content-Length", "0");
            req.Headers.Add("Max-Forwards", "70");

            Send(req);
            Packet pkt = Receive();

            if (pkt is SIPResponse)
            {
                SIPResponse resp = (pkt as SIPResponse);
                if (resp.ResponseCode == 401)
                {
                    req.Headers["CSeq"].Value = "165 REGISTER";

                    // unauthorized, try with digest
                    string authenticate = resp.Headers["WWW-Authenticate"].Value;
                    string[] authParams = authenticate.Split(new char[] { ',' });
                    string nonceParam = authParams[authParams.Length - 1];
                    string[] nonceParams = nonceParam.Split(new char[] { '=' });
                    nonce = nonceParams[1].Substring(1, nonceParams[1].Length - 2);

                    string realm = "asterisk";
                    string ha1 = md5.HashString(mvarUserName + ":" + realm + ":" + mvarPassword);
                    string ha2 = md5.HashString(req.Method + ":" + req.Path);
                    string hash = md5.HashString(ha1 + ":" + nonce + ":" + ha2);
                    req.Headers.Insert(3, "Authorization", "Digest username=\"" + mvarUserName + "\", realm=\"" + realm + "\", nonce=\"" + nonce + "\", uri=\"" + req.Path + "\", algorithm=MD5, response=\"" + hash + "\"");

                    Send(req);
                    pkt = Receive();

                    if (pkt is Response)
                    {

                    }
                    else if (pkt is Request)
                    {
                        Request req2 = (pkt as Request);
                        if (req2.Method == "OPTIONS")
                        {
                            SIPResponse resp2 = new SIPResponse();
                            resp2.ResponseCode = 200;
                            resp2.ResponseText = "OK";
                            resp2.Headers.Add("CSeq", req2.Headers["CSeq"].Value);
                            resp2.Headers.Add("Call-ID", req2.Headers["Call-ID"].Value);
                            Send(resp2);

                            pkt = Receive();

                            SIPInviteRequest invite = new SIPInviteRequest();
                            invite.Headers.Add("CSeq", "1 INVITE");
                            invite.Subject = "sip:[email protected]";
                            invite.Headers.Add("v", "SIP/2.0/UDP 10.0.1.103:5060;branch=z9hG4bK4545d10a-bb10-1910-984c-0a0027000000;rport");
                            invite.Headers.Add("f", "\"Mike Becker\" <sip:" + mvarUserName + "@asterisk.becker-family.mbn>;tag=f840d10a-bb10-1910-984a-0a0027000000");
                            invite.Headers.Add("i", "[email protected]");
                            invite.Headers.Add("k", "100rel,replaces");
                            invite.Headers.Add("m", "\"Mike Becker\" <sip:" + mvarUserName + "@10.0.1.103:5060>");
                            invite.Headers.Add("Allow", "INVITE,ACK,OPTIONS,BYE,CANCEL,SUBSCRIBE,NOTIFY,REFER,MESSAGE,INFO,PING,PRACK");
                            invite.Headers.Add("l", "864");
                            invite.Headers.Add("c", "application/sdp");
                            invite.Headers.Add("Max-Forwards", "70");

                            string w = @"v=0
            o=- 1443585841 1 IN IP4 10.0.1.103
            s=Ekiga/4.0.2
            c=IN IP4 10.0.1.103
            t=0 0
            m=audio 5070 RTP/AVP 93 0 8 101
            a=sendrecv
            a=rtpmap:93 Speex/16000/1
            a=rtpmap:0 PCMU/8000/1
            a=rtpmap:8 PCMA/8000/1
            a=rtpmap:101 telephone-event/8000
            a=fmtp:101 0-16,32,36
            a=maxptime:20
            m=video 5072 RTP/AVP 91 31 34 110 113 112 118
            b=AS:4096
            b=TIAS:4096000
            a=sendrecv
            a=rtpmap:91 theora/90000
            a=fmtp:91 height=576;width=704
            a=rtpmap:31 h261/90000
            a=fmtp:31 CIF=1;QCIF=1
//.........这里部分代码省略.........
开发者ID:alcexhim,项目名称:Indigo,代码行数:101,代码来源:SessionInitiationProtocol.cs


注:本文中的System.Security.Cryptography.MD5CryptoServiceProvider.HashString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。