cn.zhxu.bp.utils.Base64Utils Maven / Gradle / Ivy
The newest version!
package cn.zhxu.bp.utils;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Base64Utils {
public static String encode(String str) {
return new String(
Base64.getEncoder().encode(str.getBytes(StandardCharsets.UTF_8)),
StandardCharsets.UTF_8
);
}
public static String decode(String str) {
byte[] headerBytes = str.getBytes(StandardCharsets.UTF_8);
byte[] jsonBytes = Base64.getDecoder().decode(headerBytes);
return new String(jsonBytes, StandardCharsets.UTF_8);
}
}