1 . MD5 16-bit encryption instance
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Security. cryptography;
Namespace MD5
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Console. writeline (usermd5 ("8"));
Console. writeline (getmd5str ("8"));
}
/// <Summary>
/// The MD5 16-bit encrypted password is capitalized
/// </Summary>
/// <Param name = "convertstring"> </param>
/// <Returns> </returns>
Public Static String Getmd5str ( String Convertstring)
{
Md5cryptoserviceprovider MD5 = New Md5cryptoserviceprovider ();
String T2 = Bitconverter. tostring (md5.computehash (utf8encoding. Default. getbytes (convertstring )), 4 , 8 );
T2 = T2.replace ( " - " , "" );
Return T2;
}
/// <Summary>
/// The MD5 16-bit encrypted password is lowercase
/// </Summary>
/// <Param name = "convertstring"> </param>
/// <Returns> </returns>
Public Static String Getmd5str ( String Convertstring)
{
Md5cryptoserviceprovider MD5 = New Md5cryptoserviceprovider ();
String T2 = Bitconverter. tostring (md5.computehash (utf8encoding. Default. getbytes (convertstring )), 4 , 8 );
T2 = T2.replace ( " - " , "" );
T2 = t2.tolower ();
ReturnT2;
}
/// <Summary>
/// MD5 32-bit encryption
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Static String Usermd5 ( String Str)
{
String Cl = STR;
String PWD = "" ;
MD5 = Md5.create (); // Instantiate an MD5 object
// After encryption, it is an array of the byte type. Pay attention to the selection of UTF-8/Unicode encoding.
Byte [] S = Md5.computehash (encoding. utf8.getbytes (CL ));
// Converts an array of the byte type to a string through a loop. This string is obtained by regular character formatting.
For ( Int I = 0 ; I < S. length; I ++ )
{
// Use the hexadecimal format of the obtained string. The characters in the format are lowercase letters. If uppercase letters (x) are used, the characters in the format are uppercase letters.
PWD = PWD + S [I]. tostring ( " X " );
}
Return PWD;
}
}
}
Using system. Security. cryptography;
Using system. text;
Public static string stringtomd5hash (string inputstring)
{
Md5cryptoserviceprovider MD5 = new md5cryptoserviceprovider ();
Byte [] encryptedbytes = md5.computehash (encoding. ASCII. getbytes (inputstring ));
Stringbuilder sb = new stringbuilder ();
For (INT I = 0; I <encryptedbytes. length; I ++)
{
SB. appendformat ("{0: X2}", encryptedbytes [I]);
}
Return sb. tostring ();
}