fix: 修正md5和下载path
parent
ae927b3cc1
commit
dfda2f208a
@ -0,0 +1,40 @@
|
|||||||
|
package com.shxy.xymanager_common.util;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class DigestUtils {
|
||||||
|
|
||||||
|
public static byte[] hash(byte[] message, String alg) throws Exception {
|
||||||
|
MessageDigest md = MessageDigest.getInstance(alg);
|
||||||
|
md.update(message);
|
||||||
|
return md.digest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String md5(byte[] message, boolean b64Encoded) throws Exception {
|
||||||
|
byte[] data = hash(message, "MD5");
|
||||||
|
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha1(byte[] message, boolean b64Encoded) throws Exception {
|
||||||
|
byte[] data = hash(message, "SHA1");
|
||||||
|
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha256(byte[] message, boolean b64Encoded) throws Exception {
|
||||||
|
byte[] data = hash(message, "SHA256");
|
||||||
|
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String md5(byte[] message) throws Exception {
|
||||||
|
return md5(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String md5(String message) throws Exception {
|
||||||
|
return md5(message.getBytes(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha1(byte[] message) throws Exception {
|
||||||
|
return sha1(message, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.shxy.xymanager_common.util;
|
||||||
|
|
||||||
|
public class HexUtils {
|
||||||
|
private static final String HEX = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
public static String byte2Hex(byte[] bytes) {
|
||||||
|
String result = "";
|
||||||
|
if (null != bytes) {
|
||||||
|
for (int i = 0; i < bytes.length; ++i) {
|
||||||
|
result = result + "0123456789ABCDEF".charAt(bytes[i] >> 4 & 15);
|
||||||
|
result = result + "0123456789ABCDEF".charAt(bytes[i] & 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] hex2Byte(String text) throws Exception {
|
||||||
|
String hexText = text;
|
||||||
|
if (text.length() % 2 == 1) {
|
||||||
|
hexText = "0" + text;
|
||||||
|
}
|
||||||
|
|
||||||
|
hexText = hexText.toLowerCase();
|
||||||
|
int len = hexText.length() / 2;
|
||||||
|
byte[] result = new byte[len];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
String s = hexText.substring(2 * i, 2 * i + 2);
|
||||||
|
result[i] = (byte) (Integer.parseInt(s, 16) & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue