12345678910111213141516171819202122232425262728293031 |
- package com.huimv.business.utils;
- import org.springframework.stereotype.Component;
- import java.io.UnsupportedEncodingException;
- import java.util.Base64;
- /**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
- @Component
- public class TextUtil {
- //base64编码
- public String encode(String text) throws UnsupportedEncodingException {
- final Base64.Encoder encoder = Base64.getEncoder();
- final byte[] textByte = text.replaceAll(" ", "").getBytes("UTF-8");
- return encoder.encodeToString(textByte);
- }
- //base64解码
- public String decode(String encodedText) throws UnsupportedEncodingException {
- final Base64.Decoder decoder = Base64.getDecoder();
- return new String(decoder.decode(encodedText.toString().replace("\r\n", "")), "UTF-8");
- }
- }
|