123456789101112131415161718192021222324252627282930 |
- package com.mooctest.util;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import java.util.Base64;
- public class EncodeUtil {
- public static String strConvertBase(String str) {
- if(null != str){
- Base64.Encoder encoder = Base64.getEncoder();
- return URLEncoder.encode(encoder.encodeToString(str.getBytes()));
- }
- return "";
- }
- public static String baseConvertStr(String str) {
- if(null != str){
- Base64.Decoder decoder = Base64.getDecoder();
- try {
- return new String(decoder.decode(str.getBytes()), "utf-8");
- } catch (UnsupportedEncodingException e) {
- return null;
- }
- }
- return "";
- }
- }
|