标签:style blog http java color os
import java.security.MessageDigest; import java.util.*; public class Hello2{ public static void main(String[] args) throws Exception{ Random r = new Random();//从用户的用户名中解析出一个随机数 int ran = 1+r.nextInt(10); System.out.println("ran is:"+ran); //即使是相同的密码,加密的结果也不相同。salt盐值 String pwd = ""; MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] bt = md5.digest(pwd.getBytes()); StringBuffer sb = new StringBuffer(); for(int i=0;i<bt.length;i++){ int mm = bt>>ran; mm = Math.abs(mm); if(mm<16){ mm+=16; } String hex = Integer.toHexString(mm); System.out.println("mm:"+mm+","+hex); sb.append(hex); } System.out.println(sb.toString()+","+sb.toString().length()); } }
标签:style blog http java color os
原文地址:http://www.cnblogs.com/xiaweifeng/p/3700005.html