package shop.alien.util.encryption;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * base64加密解密
 *
 * @author ssk
 * @version 1.0
 * @date 2020/1/17 10:25
 */
public class Base64Util {

    /**
     * base64加密
     *
     * @return 加密字符串
     */
    public String encode(String str) {
        return Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * base64解密
     *
     * @return 解密字符串
     */
    public String decode(String str) {
        byte[] asBytes = Base64.getDecoder().decode(str);
        return new String(asBytes, StandardCharsets.UTF_8);
    }

    public static void main(String[] args) {
        Base64Util base64Util = new Base64Util();
        String encodeStr = base64Util.encode("123456");
        System.out.println("加密:" + encodeStr);
        System.out.println("解密:" + base64Util.decode(encodeStr));
    }

}
