Java生成MD5字符串

来源:互联网 发布:农村淘宝 土豪村 编辑:程序博客网 时间:2024/06/05 02:58
public class MD5Utils {public static String encode(String password) {try {MessageDigest digest = MessageDigest.getInstance("MD5");byte[] bytes = digest.digest(password.getBytes());StringBuffer sb = new StringBuffer();for (byte b : bytes) {int i = b & 0xff;// 获取低8位内容String hexString = Integer.toHexString(i);if (hexString.length() == 1) {hexString = "0" + hexString;}sb.append(hexString);}String md5 = sb.toString();return md5;} catch (NoSuchAlgorithmException e) {e.printStackTrace();}return null;}}

0 0
原创粉丝点击