EncodeUtil.java 773 B

123456789101112131415161718192021222324252627282930
  1. package com.mooctest.util;
  2. import java.io.UnsupportedEncodingException;
  3. import java.net.URLEncoder;
  4. import java.util.Base64;
  5. public class EncodeUtil {
  6. public static String strConvertBase(String str) {
  7. if(null != str){
  8. Base64.Encoder encoder = Base64.getEncoder();
  9. return URLEncoder.encode(encoder.encodeToString(str.getBytes()));
  10. }
  11. return "";
  12. }
  13. public static String baseConvertStr(String str) {
  14. if(null != str){
  15. Base64.Decoder decoder = Base64.getDecoder();
  16. try {
  17. return new String(decoder.decode(str.getBytes()), "utf-8");
  18. } catch (UnsupportedEncodingException e) {
  19. return null;
  20. }
  21. }
  22. return "";
  23. }
  24. }