MD5 encryption algorithm in Java full version

Source: Internet
Author: User

In the Java software development process, some data will inevitably be encrypted, so Java provides the messagedigest implementation of the text encryption algorithm, the following is a text to encrypt the MD5 cryptographic tool Class code example:


Package Net.yuerwan.commons.util;import Java.security.messagedigest;import Java.security.NoSuchAlgorithmException ; Import org.apache.commons.lang.stringutils;/*** function: MD5 Encryption Tool Class * Description: Reprint Please specify: Wenbo Station---http://www.iwwenbo.com*/public Class Md5util {/*** 1.32-bit lowercase MD5 encryption of text * @param plaintext the text to be encrypted * @return encrypted content */public static String texttomd5l32 (Strin G plaintext) {String result = null;//First determines if NULL if (Stringutils.isblank (plaintext)) {return null;} try{//first Instantiates and initializes messagedigest MD = messagedigest.getinstance ("MD5");//Gets an OS default byte-encoded format byte array byte[] Btinput = Plaintext.getbytes ();//processing of the resulting byte array md.update (BTINPUT);//hash calculation and return result byte[] Btresult = Md.digest ();// The length of the data obtained after hashing stringbuffer sb = new StringBuffer (); for (byte b:btresult) {int bt = B&AMP;0XFF;IF (bt<16) {sb.append (0) ;} Sb.append (Integer.tohexstring (BT));} result = Sb.tostring ();} catch (NoSuchAlgorithmException e) {e.printstacktrace ();} return result;} /*** 2.32-bit MD5 Capital encryption for text * @param plaintext the text to be encrypted * @return encrypted content */public static String texttomd5u32 (StRing plaintext) {if (Stringutils.isblank (plaintext)) {return null;} String result = Texttomd5l32 (plaintext); return result.touppercase ();}
full read >> Click me;

MD5 encryption algorithm in Java full version

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.