package com.droiddev.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.util.Log;

/**
 * MD5 util: this util is used to eccrypt string with MD5.
 *
 * @author Vincent Cheung
 * @since  May. 11, 2014
 */
public class MD5
{
	private static final String TAG = "MD5";
	
	public static String Encrypt(String origin) {
		MessageDigest md5 = null;
		
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			Log.d(TAG, "[md5 encrypt error]: " +e.getMessage());
			e.printStackTrace();
		}
		
		char[] charArray = origin.toCharArray();
		byte[] byteArray = new byte[charArray.length];
		
		for (int i = 0; i < charArray.length; i ++) {
			byteArray[i] = (byte) charArray[i];
		}
		
		byte[] md5Bytes = md5.digest(byteArray);
		/* transfer the result to hex string */
		StringBuffer hexValue = new StringBuffer();
		for (int i = 0; i < md5Bytes.length; i ++) {
			int val = ((int) md5Bytes[i]) & 0xff;
			if (val < 16) {
				hexValue.append("0");
			}
			
			hexValue.append(Integer.toHexString(val));
		}
		
		return hexValue.toString();
	}
}

@@ -9,24 +9,70 @@
 com.
-droiddev.utils;%0A
+cooler.utils;%0D%0A%0D%0Aimport java.io.UnsupportedEncodingException;%0D
 %0Aimp
@@ -103,16 +103,17 @@
 eDigest;
+%0D
 %0Aimport 
@@ -151,17 +151,19 @@
 ception;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -183,13 +183,16 @@
 Log;
-%0A
+%0D%0A%0D
 %0A/**
+%0D
 %0A * 
@@ -246,19 +246,21 @@
 ith MD5.
+%0D
 %0A *
+%0D
 %0A * @aut
@@ -277,16 +277,17 @@
 t Cheung
+%0D
 %0A * @sin
@@ -307,12 +307,14 @@
 2014
+%0D
 %0A */
+%0D
 %0Apub
@@ -330,12 +330,17 @@
  MD5
+%0D
 %0A%7B
-%0A%09
+%0D%0A    
 priv
@@ -373,16 +373,79 @@
 G = 
-%22
 MD5
+.class.getSimpleName();%0D%0A%09private static final String NULL = %22
 %22;
+%0D
 %0A%09
+%0D
 %0A%09pu
@@ -487,16 +487,17 @@
 rigin) %7B
+%0D
 %0A%09%09Messa
@@ -520,19 +520,21 @@
 ull;
+%0D
 %0A%09%09
+%0D
 %0A%09%09try %7B
 %0A%09%09%09
@@ -529,16 +529,17 @@
 %0A%09%09try %7B
+%0D
 %0A%09%09%09md5 
@@ -573,16 +573,17 @@
 (%22MD5%22);
+%0D
 %0A%09%09%7D cat
@@ -619,16 +619,17 @@
 e) %7B
+%0D
 %0A%09%09%09Log.
 d(TA
@@ -624,17 +624,17 @@
 %0A%09%09%09Log.
-d
+e
 (TAG, %22%5B
@@ -656,16 +656,17 @@
 or%5D: %22 +
+ 
 e.getMes
@@ -677,228 +677,245 @@
 ());
+%0D
 %0A%09%09%09
-e.printStackTrace();
+return NULL;%0D
 %0A%09%09%7D
+ %0D
 %0A%09%09
+%0D
 %0A%09%09
-char%5B%5D charArray = origin.toCharArray();%0A%09%09byte%5B%5D byteArray = new byte%5BcharArray.length%5D;%0A%09%09%0A%09%09for (int i = 0; i %3C charArray.length; i ++
+byte%5B%5D byteArray = null;%0D%0A%09%09try %7B%0D%0A%09%09%09byteArray = origin.getBytes(%22UTF-8%22);%0D%0A%09%09%7D catch (UnsupportedEncodingException e
 ) %7B
+%0D
 %0A%09%09%09
-byteArray%5Bi%5D = (byte) charArray%5Bi%5D;
+Log.e(TAG, %22%5Bmd5 encrypt error%5D: %22 + e.getMessage());%0D%0A%09%09%09return NULL;%0D
 %0A%09%09%7D
+%0D
 %0A%09%09
+%0D
 %0A%09%09b
@@ -953,16 +953,17 @@
 eArray);
+%0D
 %0A%09%09/* tr
@@ -996,16 +996,17 @@
 tring */
+%0D
 %0A%09%09Strin
@@ -1043,16 +1043,17 @@
 uffer();
+%0D
 %0A%09%09for (
@@ -1091,16 +1091,17 @@
  i ++) %7B
+%0D
 %0A%09%09%09int 
@@ -1133,16 +1133,17 @@
  & 0xff;
+%0D
 %0A%09%09%09if (
@@ -1153,16 +1153,17 @@
  %3C 16) %7B
+%0D
 %0A%09%09%09%09hex
@@ -1184,17 +1184,20 @@
 0%22);
+%0D
 %0A%09%09%09%7D
+%0D
 %0A%09%09%09
+%0D
 %0A%09%09%09
@@ -1242,15 +1242,18 @@
 l));
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%09
+%0D
 %0A%09%09r
@@ -1282,10 +1282,13 @@
 g();
+%0D
 %0A%09%7D
+%0D
 %0A%7D
+%0D
 %0A

fix bug in MD5 when encypt chinese