TextUtil.java 919 B

12345678910111213141516171819202122232425262728293031
  1. package com.huimv.business.utils;
  2. import org.springframework.stereotype.Component;
  3. import java.io.UnsupportedEncodingException;
  4. import java.util.Base64;
  5. /**
  6. * @Project : huimv.shiwan
  7. * @Package : com.huimv.biosafety.uface.controller
  8. * @Description : TODO
  9. * @Version : 1.0
  10. * @Author : ZhuoNing
  11. * @Create : 2020-12-25
  12. **/
  13. @Component
  14. public class TextUtil {
  15. //base64编码
  16. public String encode(String text) throws UnsupportedEncodingException {
  17. final Base64.Encoder encoder = Base64.getEncoder();
  18. final byte[] textByte = text.replaceAll(" ", "").getBytes("UTF-8");
  19. return encoder.encodeToString(textByte);
  20. }
  21. //base64解码
  22. public String decode(String encodedText) throws UnsupportedEncodingException {
  23. final Base64.Decoder decoder = Base64.getDecoder();
  24. return new String(decoder.decode(encodedText.toString().replace("\r\n", "")), "UTF-8");
  25. }
  26. }