cn.zhxu.bp.utils.CodecUtils Maven / Gradle / Ivy
The newest version!
package cn.zhxu.bp.utils;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
/**
* @author Troy.Zhou
*/
public class CodecUtils {
public static String encodeToBase64(String source) {
if (source == null) return null;
return Base64.getEncoder().encodeToString(source.getBytes(StandardCharsets.UTF_8));
}
public static String decodeFromBase64(String base64) {
if (base64 == null) return null;
byte[] bytes = Base64.getDecoder().decode(base64);
return new String(bytes, StandardCharsets.UTF_8);
}
}