You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
package com.fr.password.tool.util; |
|
|
|
import cn.hutool.json.JSONObject; |
|
import cn.hutool.json.JSONUtil; |
|
import com.fr.password.bean.RequestBean; |
|
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; |
|
import sun.misc.BASE64Decoder; |
|
import sun.misc.BASE64Encoder; |
|
|
|
import java.io.IOException; |
|
import java.io.UnsupportedEncodingException; |
|
import java.net.URLDecoder; |
|
|
|
/** |
|
* 编码相关的工具类 |
|
*/ |
|
public class EncodeUtil { |
|
public static String byte2Base64(byte[] bytes) { |
|
BASE64Encoder encoder = new BASE64Encoder(); |
|
return encoder.encode(bytes); |
|
} |
|
|
|
public static byte[] base642Byte(String base64Key) throws IOException { |
|
BASE64Decoder decoder = new BASE64Decoder(); |
|
return decoder.decodeBuffer(base64Key); |
|
} |
|
|
|
public static String byte2HexString(byte[] bytes) { |
|
return ByteUtils.toHexString(bytes); |
|
} |
|
|
|
public static RequestBean parseBody(String content) throws UnsupportedEncodingException { |
|
String originContent = URLDecoder.decode(content, "UTF8"); |
|
JSONObject jsonObject = JSONUtil.parseObj(originContent); |
|
String key = (String) jsonObject.get("key"); |
|
String text = (String) jsonObject.get("text"); |
|
return new RequestBean(key, text); |
|
} |
|
}
|
|
|