标签:style blog color io os ar for sp div
//消息摘要:将任意长度的字符数组处理成定长的字符数组,用于确保原字符串不被修改, //也可以用做密码确认,如果密码一致,则MD5产生后的值必然一致,否则不相同 public class DataUtil { public static void main(String[] args) throws Exception { char[] ch={‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,}; String src= "唐"; StringBuffer sb=new StringBuffer(); byte[] b1=src.getBytes(); System.out.println("-----------"+b1.length); for(byte b:b1){ System.out.print(b+" "); } System.out.println(); MessageDigest md= MessageDigest.getInstance("MD5"); byte[] b2=md.digest(b1); System.out.println("-------"+b2.length); for(byte b:b2){ System.out.print(b+" "); //高四位 sb.append(ch[b>>4 & 0x0F]); //低四位 sb.append(ch[b & 0x0F]); } System.out.println(); System.out.println(sb.length()+":"+sb.toString()); } }
标签:style blog color io os ar for sp div
原文地址:http://www.cnblogs.com/TankRuning/p/3999181.html