Using MD5 for encryption in Java

Source: Internet
Author: User
Tags md5 encryption

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

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.