Java to Password MD5

Source: Internet
Author: User

MD5, i.e. "Message-digest algorithm 5 (Information-Digest algorithm)";

MD5 transforms the "byte string" of any length into a large integer of 128bit, and it is an irreversible string transform algorithm;

1 ImportJava.math.BigInteger;2 Importjava.security.MessageDigest;3 Importjava.security.NoSuchAlgorithmException;4 5  Public classUtility {6     Staticmessagedigest messagedigest;7     StaticString pwd;8      Public Staticstring getMD5 (string plaintext) {9         Try {Ten             //generate a MD5 cryptographic calculation summary OneMessageDigest = Messagedigest.getinstance ("MD5"); A             //Digest with new message in clear text - messagedigest.update (Plaintext.getbytes ()); -             //Digest () finally determines the return MD5 hash value, and the return value is a 8-bit string. Because the MD5 hash value is a 16-bit hex value, it's actually a 8-bit character. the             //The BigInteger function converts a 8-bit string to a 16-bit hex value, represented by a string, and a hash value in string form, where 1 represents a positive number and 0 represents a negative number for 0,-1. -PWD =NewBigInteger (1, Messagedigest.digest ()). ToString (16); -          -}Catch(nosuchalgorithmexception e) { + e.printstacktrace (); -         } +         returnpwd; A     } at}

Test 123456 of MD5 for e10adc3949ba59abbe56e057f20f883e

Java to Password MD5

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.