MD5 encryption in Android

Source: Internet
Author: User
Tags md5 hash
There are a lot of materials on the Internet about MD5 encryption in Android, but the test is always different from the MD5 encryption in the website. Later I learned that the encoding method is incorrect, so I wrote one myself. Private Static final char hex_digits [] = {'0', '1', '2', '3', '4', '5', '6 ', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F '}; public static string tohexstring (byte [] B) {// string to byte stringbuilder sb = new stringbuilder (B. length * 2); For (INT I = 0; I <B. length; I ++) {sb. append (hex_digits [(B [I] & 0xf0) >>> 4]); sb. append (hex_digits [B [I] & 0x0f]);} return sb. tostring ();} Public String MD5 (string s) {try {// create MD5 hash messagedigest digest = Java. security. messagedigest. getinstance ("MD5"); Digest. update (S. getbytes (); byte messagedigest [] = digest. digest (); Return tohexstring (messagedigest);} catch (nosuchalgorithmexception e) {e. printstacktrace ();} return "";}
Related Article

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.