以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]MD5加密求助,下面为java代码,求帮忙转换下  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173873)

--  作者:wh123
--  发布时间:2021/12/20 17:29:00
--  [求助]MD5加密求助,下面为java代码,求帮忙转换下
public String doContentMD5(String str) throws Exception {
byte[] md5Bytes = null;
MessageDigest md5 = null;
String contentMD5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
// 计算md5函数
md5.update(str.getBytes("UTF-8"));
// 获取文件MD5的二进制数组(128位)
md5Bytes = md5.digest();
// 把MD5摘要后的二进制数组md5Bytes使用Base64进行编码(而不是对32位的16进制字符串进行编码)
contentMD5 = new String(Base64.encodeBase64(md5Bytes), "UTF-8");
} catch (NoSuchAlgorithmException e) {
String msg = MessageFormat.format("不支持此算法: {0}", e.getMessage());
Exception ex = new Exception(msg);
ex.initCause(e);
throw ex;
} catch (UnsupportedEncodingException e) {
String msg = MessageFormat.format("不支持的字符编码: {0}", e.getMessage());
Exception ex = new Exception(msg);
ex.initCause(e);
throw ex;
}
return contentMD5;
}

--  作者:有点蓝
--  发布时间:2021/12/20 17:36:00
--  
java看不懂。提供一下原版的开发文档看看
--  作者:wh123
--  发布时间:2021/12/20 17:42:00
--  
把MD5摘要后的二进制数组md5Bytes使用Base64进行编码(而不是对32位的16进制字符串进行编码)


文档这么说的,然后就给了JAVA代码