MD5 Encryption--32-bit 16 binary lowercase

Source: Internet
Author: User
Tags md5 encryption

 Public classTtgameMd5 { Public Final Staticstring MD5 (String str) {CharHexdigits[] = {//the character used to convert a byte into a 16 binary representation' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ',                ' E ', ' F ' }; Try {            byte[] strtemp =str.getbytes (); MessageDigest mdtemp= Messagedigest.getinstance ("MD5");            Mdtemp.update (strtemp); byteTmp[] = Mdtemp.digest ();//the MD5 evaluates to a 128-bit long integer,//in bytes, that's 16 bytes .            CharStrs[] =New Char[16 * 2];//each byte is represented by a 16 binary, using two characters,//so 32 characters are required to represent 16 binary            intk = 0;//represents the corresponding character position in the transformation result             for(inti = 0; I < 16; i++) {//starting with the first byte, each byte of the MD5//Convert to 16-character conversion                byteBYTE0 = Tmp[i];//take the first I bytestrs[k++] = hexdigits[byte0 >>> 4 & 0xf];//takes a 4-bit numeric conversion in bytes,//>>> moves the symbol bit right with the right shift for logicstrs[k++] = hexdigits[byte0 & 0xf];//the number conversion of the lower 4 bits in the fetch byte            }//return new String (STRs). toUpperCase ();//converted result to string            return NewString (STRs);//converted result to string}Catch(Exception e) {return NULL; }    }

MD5 Encryption--32-bit 16 binary lowercase

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.