All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy