How to implement simple MD5 encryption with Android _android

Source: Internet
Author: User
Tags md5 md5 encryption md5 hash

This article is an example of how Android implements simple MD5 encryption. Share to everyone for your reference, specific as follows:

Online about Android under the MD5 encrypted data a lot, but the test is always the same as the site's MD5 encryption is not the same, then know that the encoding is not the way, so they wrote one.

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); c5/>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 "";
}

For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", "Android Basic Components Usage Summary", " Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

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.