赞
踩
import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5Util { public static String md5(String data) { byte[] digest = null; try { MessageDigest md5 = MessageDigest.getInstance("md5"); digest = md5.digest(data.getBytes(StandardCharsets.UTF_8)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } assert digest != null; String s = new BigInteger(1, digest).toString(16);//转换为16进制数 if (s.length() < 32) //小于32位补0 s = String.format("%32s", s).replace(" ", "0"); return s; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。