JAvaはmd 5暗号化を実現

2297 ワード

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());

  }

}