package com.crm.rely.backend.util;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * @program: cwg-my-base
 * @description:
 * @author: houn
 * @create: 2019-08-02 09:52
 */
public class Base64Util {

    public static String toBase64String(String str) {

        String base64Sign = null;
        try {
            base64Sign = Base64.getEncoder().encodeToString(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return base64Sign;
    }

    public static String toBase64String(byte[] byteArray) {

        String base64Str = Base64.getEncoder().encodeToString(byteArray);

        return base64Str;
    }

    public static byte[] toByteArray(String str) {

        byte[] byteArray = Base64.getDecoder().decode(str);

        return byteArray;
    }

    public static String toBase64DecoderString(byte[] byteArray) {
        String base64Decodedr = null;
        try {
            base64Decodedr = new String(byteArray);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return base64Decodedr;
    }
}
