/**
* Created by gb on 2018/1/24.
*/
public class MD5Utils {
/**
* 将字符串转成MD5值
*
* @param string
* @return
*/
public static String stringToMD5(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 0xFF) < 0x10)
hex.append("0");
hex.append(Integer.toHexString(b & 0xFF));
}
return hex.toString();
}
}
android MD5
最新推荐文章于 2021-05-27 04:56:48 发布
本文介绍了一种将字符串转换为MD5加密格式的实用方法。通过使用Java编程语言,提供了具体的实现代码,包括如何处理可能出现的异常情况。该方法适用于需要进行基本MD5加密的应用场景。
179

被折叠的 条评论
为什么被折叠?



