Java MD5 Tool Class

Source: Internet
Author: User
Tags md5 encryption

  1. Package com.common.tools;
  2. Import Java.security.MessageDigest;
  3. /**
  4. * MD5 Encryption Tool Class
  5. * < function Detail Description >
  6. *
  7. * @author Chenlujun
  8. * @version [version number, October 1, 2014]
  9. * @see [related classes/methods]
  10. * @since [Product/module Version]
  11. */
  12. Public abstract class Md5tools
  13. {
  14. public final static string MD5 (string pwd) {
  15. //characters used for encryption
  16. char md5string[] = { ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ' , ' 6 ', ' 7 ', ' 8 ', ' 9 ',
  17. ' A ', ' B ', ' C ', ' D ', ' E ', ' F '};
  18. try {
  19. //Use the default character set of the platform to encode this String into a byte sequence and store the result in a new byte array
  20. byte[] btinput = Pwd.getbytes ();
  21. The //Information digest is a secure, one-way hash function that receives data of any size and outputs a fixed-length hash value.
  22. MessageDigest mdinst = messagedigest.getinstance ("MD5");
  23. The //messagedigest object processes the data by using the Update method, updating the digest with the specified byte array
  24. Mdinst.update (Btinput);
  25. after the summary update, hash calculations are performed by calling Digest () to obtain ciphertext
  26. byte[] md = Mdinst.digest ();
  27. //Convert ciphertext to 16 binary string form
  28. int j = md.length;
  29. char str[] = new char[j * 2];
  30. int k = 0;
  31. For (int i = 0; i < J; i++) { //i = 0
  32. byte byte0 = md[i]; //95
  33. str[k++] = md5string[byte0 >>> 4 & 0xf]; //5
  34. str[k++] = md5string[byte0 & 0xf]; //F
  35. }
  36. //Returns the encrypted string
  37. return new String (str);
  38. } catch (Exception e) {
  39. return null;
  40. }
  41. }
  42. }
  43. Transfer from http://blog.csdn.net/clj198606061111/article/details/39722781

Java MD5 Tool Class

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.