【Java】MD5加密

Dsp Tian發表於2017-09-02
package sdfg;

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

public class sdfg {
    
    public static String createMD5(String pw) throws NoSuchAlgorithmException
    {
        MessageDigest md;
        md=MessageDigest.getInstance("MD5");
        md.update(pw.getBytes());
        String re=new BigInteger(1,md.digest()).toString(16);                
        return re;        
    }
    
    public static void main(String[] args) throws NoSuchAlgorithmException 
    {
        String pw="asdfaf";
        
        System.out.println(createMD5(pw));
    }
}

 

相關文章