ASP. NET MD5 Cryptographic functions (C #)

Source: Internet
Author: User

Using the following method, you can enter data directly, back to the MD5 encrypted code

<summary> ///UseMd5Encryption </summary> <param name= "Sourcein" >The data entered</param> <returns></returns> PublicStaticStringMD5 (StringSourcein) {MD5CryptoServiceProvider MD5CSP=NewMD5CryptoServiceProvider ();   byte[] Md5source = System.Text.Encoding.UTF8.GetBytes (Sourcein);    byte[] md5out = Md5csp.computehash (Md5source);    return convert.tobase64string (md5out); }

The above is only applicable to. Net md5 encryption, but now many companies are in asp asp.net stage, in order not to change the original teaching large user database, we need to find a kind of asp md5 after the same result of encryption, the following code is what I used to give you reference: Yellow part code

Using System; Using System.Drawing; Using System.Collections; Using System.ComponentModel; Using System.Windows.Forms; Using System.Data;

namespace WindowsApplication2 {//<summary>//Form1 summary description. ///</summary> public class Form1: System.Windows.Forms.Form {  Private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox TextBox1;   Private System.Windows.Forms.TextBox TextBox2;   Private System.Windows.Forms.Label Label1;   Private System.Windows.Forms.Label Label2;   Private System.Windows.Forms.TextBox TextBox3;   Private System.Windows.Forms.Label label3;  //<summary>  // required designer variables.  //</summary>   Private System.ComponentModel.Container components = null;

  public Form1 ()   {  //  //Windows The form designer supports the required   //    InitializeComponent ();

  //  //TODO: InitializeComponent add any constructor code after call   // 

<summary>/// clean up all resources in use. // </summary> protected override void Dispose (bool disposing) {if (disposing) {if (compon Ents = null) {components.     Dispose (); }} base.   Dispose (disposing); }

#region WindowsCode generated by the form designer<summary>//The methods required by the designer support-Do not use the Code editor to modify///The contents of this method.</summary> private void InitializeComponent () {this.button1 = new System.Windows.Forms.Button ();    This.textbox1 = new System.Windows.Forms.TextBox ();    This.textbox2 = new System.Windows.Forms.TextBox ();    This.label1 = new System.Windows.Forms.Label ();    This.label2 = new System.Windows.Forms.Label ();    This.textbox3 = new System.Windows.Forms.TextBox ();    This.label3 = new System.Windows.Forms.Label (); This.    SuspendLayout ();    Button1//this.button1.Location = new System.Drawing.Point (200, 96);    This.button1.Name = "Button1";    This.button1.TabIndex = 0; This.button1.Text = "Encryption";    This.button1.Click + = new System.EventHandler (This.button1_click);   //  //TextBox1   //   this.textBox1.Location = new System.Drawing.Point (8 8, 24);    this.textBox1.Name = "TextBox1";    this.textBox1.Size = new System.Drawing.Size (120, 21);    This.textBox1.TabIndex = 1;    this.textBox1.Text = "";   //  //TextBox2   //   this.textBox2.Location = new System.Drawing.Point (8 8, 64);    this.textBox2.Name = "TextBox2";    this.textBox2.Size = new System.Drawing.Size (312, 21);    This.textBox2.TabIndex = 2;    this.textBox2.Text = "";   //  //Label1   //   this.label1.Location = new System.Drawing.Point (48, 32 );    this.label1.Name = "Label1";    this.label1.Size = new System.Drawing.Size (32, 16);    This.label1.TabIndex = 3;    This.label1.Text = " Password";    Label2//this.label2.Location = new System.Drawing.Point (16, 64);    This.label2.Name = "Label2";    This.label2.Size = new System.Drawing.Size (64, 16);    This.label2.TabIndex = 4; This.label2.Text = "MD5After encryption";    TextBox3//this.textBox3.Location = new System.Drawing.Point (280, 24);    This.textBox3.Name = "TextBox3";    This.textBox3.Size = new System.Drawing.Size (120, 21);    This.textBox3.TabIndex = 5;    This.textBox3.Text = "";    LABEL3//this.label3.Location = new System.Drawing.Point (216, 32);    This.label3.Name = "Label3";    This.label3.Size = new System.Drawing.Size (48, 16);    This.label3.TabIndex = 6; This.label3.Text = " offset ";   //  //Form1   //   this. AutoScaleBaseSize = new System.Drawing.Size (6, 14);    this. ClientSize = new System.Drawing.Size (416, 133);    this. Controls.Add (THIS.LABEL3);    this. Controls.Add (THIS.TEXTBOX3);    this. Controls.Add (THIS.LABEL2);    this. Controls.Add (THIS.LABEL1);    this. Controls.Add (THIS.TEXTBOX2);    this. Controls.Add (This.textbox1);    this. Controls.Add (This.button1);    this. Name = "Form1";    this. Text = "Form1";    this. Load + = new System.EventHandler (this. Form1_Load);    this. ResumeLayout (false);

} #endregion

<summary>/// The main entry point of the application.   // </summary> [STAThread] static void Main () {Application.Run (New Form1 ()); }

 //<summary>  // /</summary>  /<param name= "Sdatain" > The string that needs to be encrypted </ param>  //<param name= "move" > offset </param >  //<returns>sdatain After the encrypted string </ Returns>

  public string GetMD5 (String sdatain,string move)   {   System.Security.Cryptography.MD5CryptoServiceProvider md5=new System.Security.Cryptography.MD5CryptoServiceProvider ();    Byte[]bytvalue,bythash;    Bytvalue = System.Text.Encoding.UTF8.GetBytes (Move+sdatain);    Bythash = Md5.computehash (Bytvalue);    MD5. Clear ();    string stemp= "";    for (int i=0;i<bythash.length;i++)    {    stemp+=bythash[i]. ToString ("X"). PadLeft (2, ' 0 ');   }    return stemp;  }   private void Form1_Load (object sender, System.EventArgs e)   {   }

private void Button1_Click (object sender, System.EventArgs e) {this.textBox2.Text = GetMD5 (this.textbox1.text,this.   TextBox3.Text); } } }

ASP. NET MD5 Cryptographic functions (C #)

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.