JAVA,ANDROID,MD5 Encryption algorithm Implementation code (16-bit, 32-bit) _java

Source: Internet
Author: User
Tags md5 md5 encryption stringbuffer

As shown below:

Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;

public class Md5 {public

  static String getMD5 (string val) throws nosuchalgorithmexception{ 
    messagedigest MD5 = Me Ssagedigest.getinstance ("MD5"); 
    Md5.update (Val.getbytes ()); 
    byte[] m = md5.digest ()//Encrypted return  
    getString (m); 
  private static String getString (byte[] b) { 
    StringBuffer buf = new StringBuffer (); 
     for (int i = 0; i < b.length i + +) { 
    	 int a = B[i];
	     if (a<0)
	    	 a+=256;
	     if (a<16)
	    	 buf.append ("0");
	     Buf.append (Integer.tohexstring (a)); 		
     return buf.tostring (); 32-bit	
or return buf.tostring (). substring (8,24);  //16-bit

The above is small series for everyone to bring the implementation code (16-bit, 32-bit) of the JAVA,ANDROID,MD5 encryption algorithm, I hope to help you, a lot of support cloud Habitat Community ~

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.