Java MD5 Encryption algorithm

Source: Internet
Author: User

PACKAGE&NBSP;COM.SOAP.UTIL;IMPORT&NBSP;JAVA.SECURITY.MESSAGEDIGEST;/**&NBSP;*&NBSP;MD5 Encryption  *  @author &NBSP;ROGER&NBSP;*/PUBLIC&NBSP;CLASS&NBSP;MD5UTIL&NBSP;{/**&NBSP;*&NBSP;MD5 encryption   Generate 32-bit MD5 code  *   *  @param   String to encrypt  *  @return   return 32-bit MD5 code  */public static String  Md5encode (STRING&NBSP;INSTR)  {try {messagedigest md5 = null;try {md5 =  messagedigest.getinstance ("MD5");}  catch  (exception e)  {system.out.println (e.tostring ()) e.printstacktrace ();return  "";} Byte[] bytearray = instr.getbytes ("UTF-8"); Byte[] md5bytes = md5.digest ( ByteArray); Stringbuffer hexvalue = new stringbuffer ();for  (int i = 0; i  < md5bytes.length; i++)  {int val =  ((int)  md5bytes[i])  &  0xff;if  (val < 16)  {hexvalue.append ("0");} Hexvalue.append (Integer. Tohexstring (Val));} Return hexvalue.tostring ();}  catch  (exception e)  {e.printstacktrace ();} Return null;} Public static void main (String[] args)  {try {system.out.println ( Md5util.md5encode ("123456"));}  catch  (exception e)  {e.printstacktrace ();}}


Java MD5 Encryption algorithm

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.