编码和解码

public static String toBase64String(String value) throws UnsupportedEncodingException {
if (value == null || value.isEmpty()) {
return "";
}
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
return java.net.URLEncoder.encode(new String(Base64.getEncoder().encode(bytes)), "UTF-8");
}

public static String UnBase64String(String value) throws UnsupportedEncodingException {
if (value == null || value.isEmpty()) {
return "";
}
String decodeValue= java.net.URLDecoder.decode(value, "UTF-8");
byte[] decodedBytes = Base64.getDecoder().decode(decodeValue);
return new String(decodedBytes,StandardCharsets.UTF_8);
}
posted @ 2025-05-19 10:16  筱老邪  阅读(9)  评论(0)    收藏  举报