MD5 Summary Algorithm Example

Source: Internet
Author: User

Package Com.soufun.com;import Java.io.unsupportedencodingexception;import Java.security.messagedigest;import java.security.nosuchalgorithmexception;/** * @author WHD Data August 13, 2015 */public class Md5test {//MD5 one-way encrypted public static void Main (string[] args) throws nosuchalgorithmexception,unsupportedencodingexception {String str = "HELLOMD digest algorithm Start"; System.out.println ("original value" + str); SYSTEM.OUT.PRINTLN ("Encrypted" + MD5TEST.AFTERMD5 (str)); String digest = MD5TEST.AFTERMD5 (str); System.out.println (Digest.equals (MD5TEST.AFTERMD5 (str))); public static string afterMD5 (String str) throws Nosuchalgorithmexception,unsupportedencodingexception {//Gets MD5 encrypted object, You can also get the SHA encryption object MessageDigest MD5 = messagedigest.getinstance ("MD5"), or//To get the input information using the specified encoding method to obtain the byte byte[] bytes = Str.getbytes (" UTF-8 ");//Use the MD5 class to obtain the digest, which is the encrypted byte md5.update (bytes); byte[] Md5encode = Md5.digest (); StringBuffer buffer = new StringBuffer (), for (int i = 0; i < md5encode.length; i++) {//Use &0xff less than 24 high because it only accounts for 8 low int val = ((int) md5encode[i]) & 0xFf;if (Val <) {Buffer.append ("0");} Returns a string representation of an integer parameter as a 16-based (radix 16) unsigned integer. Buffer.append (Integer.tohexstring (Val));} return buffer.tostring ();}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MD5 Summary Algorithm Example

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.