C # implement RTSP digest authentication response

Source: Internet
Author: User

<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-bit encryption /// </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'); // Add 0} return ret. padleft (32, '0'); // fill 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 = "3983eb84382ba9811108fc1c2e7fb8be "; string url = "rtsp: // root: [email protected]: 554/profile1 = r"; string response = computedigestresponse (username, userpwd, realm, CMD, nonce, URL ); console. writeline (response );}}}


 
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.