Beginner: MD5 under the. NET Framework

Source: Internet
Author: User
The. NET Framework has recently found programmers in. NET project in order to avoid unnecessary resource consumption, write the MD5 algorithm to achieve this article.

. NET Framework, the MD5 implementation has been integrated into the System.Web.Security namespace with a simple call to get the result:
String result strings =system.web.security.formsauthentication.hashpasswordforstoringinconfigfile (input string, "MD5");



The following wrapper functions return the 16-bit and 32-bit MD5 cryptographic strings of the parameter str, depending on the different code parameters (preferably 16 or 32).
(16-bit string used to simulate the dynamic Network forum and other domestic common forum MD5 Implementation)



public string MD5 (string Str,int code)
{

if (code==16)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (str, "MD5"). ToLower (). Substring (8,16);
}

if (code==32)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (str, "MD5");
}

return "00000000000000000000000000000000";
}


System.Web.Security the other methods of namespace encapsulation, see MSDN.

* This is a C # as an example




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.