java md5加密

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class Test2 {

    /**
     * @param args
     * @throws NoSuchAlgorithmException
     */
    public static void main(String[] args) throws NoSuchAlgorithmException {
        // TODO Auto-generated method stub
        String password="wombat";

        MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 
        messageDigest.update(password.getBytes(),0, password.length()); 
        String hashedPass = new BigInteger(1,messageDigest.digest()).toString(16); 
        if (hashedPass.length() < 32) {
           hashedPass = "0" + hashedPass;
        }
        //加密后的密码
        System.out.println(hashedPass);
    }

}

 

 

//password:koala     values:a564de63c2d0da68cf47586ee05984d7

//password:emu     values:65d15fe9156f9c4bbffd98085992a44e

你可能感兴趣的:(java md5 加密,emu,koala)