C# 实现rtsp Digest Authentication Response

<pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace RTSP_Digest_Authentication
{
    class Program
    {
        /// <summary>
        /// MD5 32位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        static string md5(string str)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
            bytes = md5.ComputeHash(bytes);
            md5.Clear();

            string ret = "";
            for (int i = 0; i < bytes.Length; i++)
            {
                ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');//补0
            }
            return ret.PadLeft(32, '0'); //补0

        }

        private static string computeDigestResponse(string username, string userpwd, string realm, string cmd, string nonce, string url)
        {
            // The "response" field is computed as:
            //    md5(md5(<username>:<realm>:<password>):<nonce>:md5(<cmd>:<url>))
            // or, if "fPasswordIsMD5" is True:
            //    md5(<password>:<nonce>:md5(<cmd>:<url>))
            string ha1 = md5(username + ":" + realm + ":" + userpwd);
            string ha2 = md5(cmd + ":" + url);
            string response = md5(ha1 + ":" + nonce + ":" + ha2);

            return response;
        }
        static void Main(string[] args)
        {
            string username = "root";
            string userpwd = "admin";
            string realm = "Operator";
            string cmd = "DESCRIBE";
            string nonce = "3983eb84382ba9811726fc1c2e7fb8be";
            string url = "rtsp://root:[email protected]:554/profile1=r";
            string response = computeDigestResponse(username, userpwd, realm, cmd, nonce, url);
            Console.WriteLine(response);
        }
    }
}

C# 实现rtsp Digest Authentication Response

时间: 2024-07-30 19:36:16

C# 实现rtsp Digest Authentication Response的相关文章

asp.net权限认证:摘要认证(digest authentication)

asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证:摘要认证(digest authentication) 一.摘要认证由来 摘要认证是对基本认证的改进,即是用摘要代替账户密码,从而防止明文传输中账户密码的泄露 之前对摘要认证也不是很熟悉,还得感谢圆中的 parry 贡献的博文:ASP.NET Web API(三):安全验证之使用摘要认证(dige

HTTP Digest authentication

"摘要"式认证( Digest authentication)是一个简单的认证机制,最初是为HTTP协议开发的,因而也常叫做HTTP摘要,在RFC2671中描述.其身份验证机制很简单,它采用杂凑式(hash)加密方法,以避免用明文传输用户的口令.摘要认证就是要核实,参与通信的双方,都知道双方共享的一个秘密(即口令). 当服务器想要查证用户的身份,它产生一个摘要盘问(digest challenge),并发送给用户.典型的摘要盘问如下: Digest realm="iptel.

ASP.NET Web API(三):安全验证之使用摘要认证(digest authentication)

在前一篇文章中,主要讨论了使用HTTP基本认证的方法,因为HTTP基本认证的方式决定了它在安全性方面存在很大的问题,所以接下来看看另一种验证的方式:digest authentication,即摘要认证. 系列文章列表 ASP.NET Web API(一):使用初探,GET和POST数据ASP.NET Web API(二):安全验证之使用HTTP基本认证ASP.NET Web API(三):安全验证之使用摘要认证(digest authentication) 摘要认证原理 在基本认证的方式中,主

[转]asp.net权限认证:摘要认证(digest authentication)

本文转自:http://www.cnblogs.com/lanxiaoke/p/6357501.html 摘要认证简单介绍 摘要认证是对基本认证的改进,即是用摘要代替账户密码,从而防止明文传输中账户密码的泄露 之前对摘要认证也不是很熟悉,还得感谢圆中的 parry 贡献的博文:ASP.NET Web API(三):安全验证之使用摘要认证(digest authentication) 我是觉得真心不错,让我少走很多弯路.这篇文章主要是对上边引用文章的讲解,老司机可以略过. 老规矩,上摘认证的工作流

Http authentication(BASIC, DIGEST)

Http authentication....BASIC: In the context of an HTTP transaction, basic access authentication is a method for a web browser or other client program to provide a user name and password when making a request.[1] Before transmission, the user name is

RTSP Spectification

Refer: https://www.ietf.org/rfc/rfc2326.txt Network Working Group H. SchulzrinneRequest for Comments: 2326 Columbia U.Category: Standards Track A. Rao Netscape R. Lanphier RealNetworks April 1998 Real Time Streaming Protocol (RTSP) Status of this Mem

http 登录Digest认证相关知识

Digest access authentication https://en.wikipedia.org/wiki/Digest_access_authentication Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with a user's web brow

Http Authentication Java

http://docs.oracle.com/javase/7/docs/technotes/guides/net/http-auth.html Http Authentication Overview The HTTP protocol handler implements a number of authentication schemes. Sun's implementation of Java SE Version 6 supports the following: HTTP Basi

小话HTTP Authentication

什么是Authentication? 首先解释两个长的很像.容易混淆的单词,Authentication(鉴定.认证)和Authorization(授权). Authentication就是要证明你是谁.举个例子,你告诉别人你的名字叫Alice,怎么样让别人确信你就是Alice,这就是Authentication. Authorization则是当别人已经相信是你以后,你是不是被允不允许做做某件事儿.比如,当你已经证明了你就是Alice了,你可以查你自己的信用卡刷卡记录,但不能查Bob的刷卡记录