安卓 之 MD5 计算
MD5是一种神奇的算法! package cn.shilight.shiguang; import android.util.Log; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5 { public String getMd5(String source) throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("md5"); byte[] bytes = source.getBytes(); byte[] targetBytes = digest.digest(bytes); char[] characters = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; StringBuilder builder = new StringBuilder(); for (byte b : targetBytes) { int high = (b >> 4) & 15; int low = b & 15; char highChar = characters[high]; char lowChar = characters[low]; builder.append(highChar).append(lowChar); } Log.i("md5",builder.toString()); return builder.toString(); } }