设备和token

This commit is contained in:
liulu
2024-12-06 15:38:22 +08:00
parent bcf8dfb5f3
commit 04cfab2f82
25 changed files with 588 additions and 25 deletions
@@ -0,0 +1,46 @@
package com.sunyard.chsm.utils;
import org.bouncycastle.util.encoders.Hex;
import java.util.Base64;
/**
* @author liulu
* @since 2024/12/6
*/
public abstract class CodecUtils {
public static String encodeBase64(byte[] data) {
return Base64.getEncoder().encodeToString(data);
}
public static byte[] decodeBase64(String str) {
try {
return Base64.getDecoder().decode(str);
} catch (Exception var3) {
if (str.length() > 32) {
str = str.substring(0, 32) + "...";
}
String format = String.format("参数[%s]不是正确的base64格式", str);
throw new IllegalArgumentException(format);
}
}
public static String encodeHex(byte[] data) {
return Hex.toHexString(data);
}
public static byte[] decodeHex(String str) {
try {
return Hex.decode(str);
} catch (Exception var3) {
if (str.length() > 32) {
str = str.substring(0, 32) + "...";
}
String format = String.format("参数[%s]不是正确的hex格式", str);
throw new IllegalArgumentException(format);
}
}
}