Asp.net MD5 encryption function (C #)
The following method can be used to directly input data and reverse the MD5 encrypted code.
/// <Summary>
/// Use MD5 Encryption
/// </Summary>
/// <Param name = "sourcein"> input data </param>
/// <Returns> </returns>
Public static string MD5 (string sourcein)
{
Md5cryptoserviceprovider md5csp = new md5cryptoserviceprovider ();
Byte [] md5source = system. Text. encoding. utf8.getbytes (sourcein );
Byte [] md5out = md5csp. computehash (md5source );
Return convert. tobase64string (md5out );
}
The above only applies. however, many companies are currently in the ASP-to-Asp.net phase. In order not to change the original user database, we need to find the same result as the MD5 encryption of ASP. The following code is what I have used. For your reference, refer to the yellow part of the code.
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Namespace windowsapplication2
{
/// <Summary>
/// Summary of form1.
/// </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 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
//
// Todo: add Any constructor code after initializecomponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content 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 = "encrypted ";
This. button1.click + = new system. eventhandler (this. button#click );
//
// Textbox1
//
This. textbox1.location = new system. Drawing. Point (88, 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 (88, 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 = "after MD5 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. form#load );
This. resumelayout (false );
}
# Endregion
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
/// <Summary>
///
/// </Summary>
/// <Param name = "sdatain"> string to be encrypted </param>
/// <Param name = "move"> offset </param>
/// <Returns> string encrypted by sdatain </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 button#click (Object sender, system. eventargs E)
{
This. textbox2.text = getmd5 (this. textbox1.text, this. textbox3.text );
}
}
}