java自带MD5加密

   之前自己做加密的时候,都是copy一份java文件,然后做加密。但是今天看项目的源码的时候,发现同事用的是jdk自带的md5加密。所以现在附上源码:

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

public class MD5Location {
	public static String getMd5(String pInput) {
		try {
			MessageDigest lDigest = MessageDigest.getInstance("MD5");
			lDigest.update(pInput.getBytes());
			BigInteger lHashInt = new BigInteger(1, lDigest.digest());
			return String.format("%1$032X", lHashInt);
		} catch (NoSuchAlgorithmException lException) {
			throw new RuntimeException(lException);
		}
	}

	public static void main(String[] args) {
		System.out.println(MD5Location.getMd5("hello"));
	}
}


你可能感兴趣的:(java自带MD5加密)