Two common encryption methods on the Web: MD5 and sha512.
Here are two methods to use.
The following two spaces of. NET are required.
Using system. Text
Using system. Security. Cryptography
1 MD5
(Without a key, the MD5 encryption results for any text are consistent and there is a security risk) Public String Pwdbymd5 ( String Stext)
{
String PWD = "" ;
MD5 = Md5.create ();
// Encrypted is a byte array.
Byte [] S = Md5.computehash (encoding. Unicode. getbytes (stext ));
// 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 ++ )
{< br> // use a hexadecimal string format. 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;
}
2 sha512
(Text encryption with a key must be consistent only when the same key is used) Public Static String Pwdbysha512 (
String Skey, // Key
String Stext // Text to be encrypted
)
{
Byte [] Hmackey = System. Text. encoding. utf8.getbytes (skey );
Byte [] Hmacdata = System. Text. encoding. utf8.getbytes (stext );
Hmacsha512 HMAC = New Hmacsha512 (hmackey );
Cryptostream CS = New Cryptostream (stream. null, HMAC, cryptostreammode. Write );
CS. Write (hmacdata, 0 , Hmacdata. Length );
CS. Close ();
Byte [] Result = HMAC. Hash;
Return Convert. tobase64string (result ); // Returns a string of 28 bytes.
}