Asp.net MD5 usage Summary

Source: Internet
Author: User

This method can convert the characters provided by the user into garbled characters, store them, and even store them in cookies.
Hashpasswordforstoringinconfigfile is easy to use. It supports "sha1" and "MD5" encryption. Algorithm .
The following Code A simple demonstration of its usage: Copy code The Code is as follows: <% @ page Language = "C #" %>
<% @ Import namespace = "system. Web. Security" %>
<HTML>
<Head>
<Script language = "C #" runat = "server">
Public void encryptstring (Object sender, eventargs E)
{
Sha1.text = formsauthentication. hashpasswordforstoringinconfigfile (txtpassword. Text, "sha1 ");
Md5.text = formsauthentication. hashpasswordforstoringinconfigfile (txtpassword. Text, "MD5 ");
}
</SCRIPT>
</Head>
<Body>
<Form runat = "server" id = "form1">
<P>
<B> original clear text password: </B>
<Br/>
<Asp: textbox id = "txtpassword" runat = "server"/>
<Asp: button runat = "server" text = "encrypt string" onclick = "encryptstring" id = "button1"/>
</P>
<P>
<B> encrypted password in sha1: </B>
<Asp: Label id = "sha1" runat = "server"/>
</P>
<P>
<B> encrypted password in MD5: </B>
<Asp: Label id = "MD5" runat = "server"/>
</P>
</Form>
</Body>
</Html>

As you can see, this is easy to use. We can encrypt this section.ProgramEncapsulated in a function for reuse. The Code is as follows:

Copy code The Code is as follows: Public String encryptpassword (string passwordstring, string passwordformat)
{
If (passwordformat = "sha1 ")
{
Encryptpassword = formsauthortication. hashpasswordforstoringinconfigfile (passwordstring, "sha1 ");
}
Elseif (passwordformat = "MD5 ")
{
Encryptpassword = formsauthortication. hashpasswordforstoringinconfigfile (passwordstring, "MD5 ");
}
Else
{
Encryptpassword = "";
}
}

MD5 applications copy Code the code is as follows: String paykey = getpaykey (webdataparse. tryintparse (partner, 0);
string signmsgval = partner + out_orderid + userid + serverid + total_fee + policy_url + paykey;
signmsgval = system. web. security. formsauthentication. hashpasswordforstoringinconfigfile (signmsgval, "MD5 "). toupper ();
If (signmsgval = signmsg)
return true;

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.