package com.jianshui.common.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @Description base64工具类
 * @Author 巩权林
 * @Date 2021/4/16 14:48
 **/
public class Base64Util {

    /**
     * base64解密
     *
     * @param srcString
     * @return
     */
    public static String decrypt(String srcString) {
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            return new String(decoder.decodeBuffer(srcString), "UTF-8");
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * base64加密
     *
     * @param srcString
     * @return
     */
    public static String encrypt(String srcString) {
        BASE64Encoder encoder = new BASE64Encoder();
        byte[] contentByte = srcString.getBytes();
        return encoder.encode(contentByte);
    }
}
