private static void MD5(){
try {
// 获取MD5加密工具
MessageDigest md = MessageDigest.getInstance("MD5");
// 加密
byte[] digest = md.digest(mStr.getBytes());
for (byte b : digest) {
System.out.println(b);
}
// 获取二进制十六进制互转工具
HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
// 将二进制数组转换为十六进制字符串
String marshal = hexBinaryAdapter.marshal(digest);
// 输出结果
System.out.println(marshal);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void MD2(){
try {
// 获取MD2加密工具
MessageDigest md = MessageDigest.getInstance("MD2");
// 加密
byte[] digest = md.digest(mStr.getBytes());
for (byte b : digest) {
System.out.println(b);
}
// 获取二进制十六进制互转工具
HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
// 将二进制数组转换为十六进制字符串
String marshal = hexBinaryAdapter.marshal(digest);
// 输出结果
System.out.println(marshal);
} catch (Exception e) {
e.printStackTrace();
}
}
try {
// 获取MD5加密工具
MessageDigest md = MessageDigest.getInstance("MD5");
// 加密
byte[] digest = md.digest(mStr.getBytes());
for (byte b : digest) {
System.out.println(b);
}
// 获取二进制十六进制互转工具
HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
// 将二进制数组转换为十六进制字符串
String marshal = hexBinaryAdapter.marshal(digest);
// 输出结果
System.out.println(marshal);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void MD2(){
try {
// 获取MD2加密工具
MessageDigest md = MessageDigest.getInstance("MD2");
// 加密
byte[] digest = md.digest(mStr.getBytes());
for (byte b : digest) {
System.out.println(b);
}
// 获取二进制十六进制互转工具
HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
// 将二进制数组转换为十六进制字符串
String marshal = hexBinaryAdapter.marshal(digest);
// 输出结果
System.out.println(marshal);
} catch (Exception e) {
e.printStackTrace();
}
}
网络搜索:
1、计算字符串的MD5值
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
2、计算文件的MD5值