Application Blog Park for a long time, has not written. Recently overtime is too tired, today is to open a door to the blog park. in order to aim, insist.
/*** Provides a method for MD5 encryption of strings. * Class Name: ETClassMD5* Author: libingbing* Creation Time:- One-1 13:10:07* Modified time:* Revision Instructions: */
Public
class ETClassMD5 { //Encrypt token
Private
StaticString
token = "Bingblee";
Private
Staticstring dealstring (Stringstring) {StringBufferStrbuffer =
NewStringBuffer (string);
return Strbuffer. Append (
token). toString (); }
Private
Static
Char
hexdigits[] = { ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ' }; /*** MD5 strings are encrypted, and the string is internally processed for encryption. * Method Name: md5string* Author: libingbing* Creation Time:- One-1st 13:18:25 *
@paramstring that needs to be encrypted. *
@returnThe 32 after encryption is a summary. */
Public
Staticstring md5string (Stringstring) { MessageDigestinstance;
Try { //Get an example of MD5 encryption algorithm instance= MessageDigest.
getinstance ("MD5"); //Encrypt the specified string instance. Update (
dealstring(string). GetBytes ());
byte[] md5string = instance. Digest (); //Transmit into 16 binary number
Char[] result =
New
Char[md5string.length* 2];//Each bit needs to be represented by two hexadecimal digits.
int Count= 0;
for (
int Index= 0;Index<md5string.length; Index++) { result[Count++] =
hexdigits [(md5string[Index] >>> 4) & 0xf]; //High four-bit result[ Count++] =
hexdigits [md5string[Index] & 0xf]; //Low four-bit }
return
NewString (result); }
Catch(NoSuchAlgorithmExceptione) { e. Printstacktrace ();
return
NULL; } }}
Using MD5 for encryption in Java