初始化
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.webkit.WebSettings;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/9/14 15:08
|
||||
* @description:
|
||||
*/
|
||||
public class GetUtil {
|
||||
|
||||
public static String getUserAgent(Context con) {
|
||||
String userAgent = "";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
try {
|
||||
userAgent = WebSettings.getDefaultUserAgent(con);
|
||||
} catch (Exception e) {
|
||||
userAgent = System.getProperty("http.agent");
|
||||
}
|
||||
} else {
|
||||
userAgent = System.getProperty("http.agent");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0, length = userAgent.length(); i < length; i++) {
|
||||
char c = userAgent.charAt(i);
|
||||
if (c <= '\u001f' || c >= '\u007f') {
|
||||
sb.append(String.format("\\u%04x", (int) c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getDeviceId(Context con){
|
||||
return Settings.System.getString(con.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
|
||||
public class OkDate {
|
||||
private String url;
|
||||
private String type;
|
||||
private String madiaType;
|
||||
|
||||
public OkDate(String url, String type, String madiaType) {
|
||||
this.url = url;
|
||||
this.type = type;
|
||||
this.madiaType = madiaType;
|
||||
}
|
||||
|
||||
public OkDate(String url, String madiaType) {
|
||||
this.url = url;
|
||||
this.madiaType = madiaType;
|
||||
}
|
||||
|
||||
public OkDate(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public OkDate() {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMadiaType() {
|
||||
|
||||
return madiaType;
|
||||
}
|
||||
|
||||
public void setMadiaType(String madiaType) {
|
||||
this.madiaType = madiaType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.util.app.VersionUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class OkHttpUtil {
|
||||
|
||||
private static String SIGN_PASSWORD="tEzOoHXXPkak*y(BfIH(YMSiV0ZHz1Ki";
|
||||
|
||||
public static Request post(OkDate od, Context con){
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
if(od.getMadiaType()!=null && od.getMadiaType().equals("")){
|
||||
od.setMadiaType("{}");
|
||||
}
|
||||
// JSONObject jsonObject = JSON.parseObject(od.getMadiaType());
|
||||
// jsonObject.put("timestamp", DateUtil.current());
|
||||
// jsonObject.put("deviceId", GetUtil.getDeviceId(con));
|
||||
// String sign = SecureUtil.signParamsSha1(jsonObject,SIGN_PASSWORD);
|
||||
// Log.e("jsonObject",jsonObject.toString());
|
||||
// Log.e("sign",sign);
|
||||
// Map<String,Object> map=new HashMap<>();
|
||||
// map.put("data",SecurityUtil.encrypt(jsonObject.toString()));
|
||||
// Log.e("参数1",od.getMadiaType());
|
||||
// Log.e("参数2",MapUtil.mapJson(map));
|
||||
//MapUtil.mapJson(map)
|
||||
RequestBody body = RequestBody.create(mediaType,od.getMadiaType());
|
||||
Headers.Builder hb=new Headers.Builder();
|
||||
hb.add("Content-Type","application/json");
|
||||
hb.add("Cache-Control","no-cache");
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.post(body)
|
||||
.headers(hb.build())
|
||||
.addHeader("Version", VersionUtil.getVersion(con))
|
||||
//.addHeader("sign",sign)
|
||||
.removeHeader("User-Agent")
|
||||
.addHeader("User-Agent",GetUtil.getUserAgent(con))
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
public static Request posts(OkDate od, String token, Context con){
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
if(od.getMadiaType()!=null && od.getMadiaType().equals("")){
|
||||
od.setMadiaType("{}");
|
||||
}
|
||||
// JSONObject jsonObject = JSON.parseObject(od.getMadiaType());
|
||||
// jsonObject.put("timestamp", DateUtil.current());
|
||||
// jsonObject.put("deviceId", GetUtil.getDeviceId(con));
|
||||
// String sign = SecureUtil.signParamsSha1(jsonObject,SIGN_PASSWORD);
|
||||
// Log.e("jsonObject",jsonObject.toString());
|
||||
// Log.e("sign",sign);
|
||||
// Map<String,Object> map=new HashMap<>();
|
||||
// map.put("data",SecurityUtil.encrypt(jsonObject.toString()));
|
||||
// Log.e("参数1",od.getMadiaType());
|
||||
// Log.e("参数2",MapUtil.mapJson(map));
|
||||
|
||||
//MapUtil.mapJson(map)
|
||||
RequestBody body = RequestBody.create(mediaType,od.getMadiaType());
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("Version", VersionUtil.getVersion(con))
|
||||
//.addHeader("sign",sign)
|
||||
.removeHeader("User-Agent")
|
||||
.addHeader("User-Agent",GetUtil.getUserAgent(con))
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static Request get(OkDate od){
|
||||
Headers.Builder hb=new Headers.Builder();
|
||||
hb.add("Content-Type","application/json");
|
||||
hb.add("Cache-Control","no-cache");
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.get()
|
||||
.headers(hb.build())
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static Request get(OkDate od,String token){
|
||||
Headers.Builder hb=new Headers.Builder();
|
||||
hb.add("Content-Type","application/json");
|
||||
hb.add("Cache-Control","no-cache");
|
||||
hb.add("Authorization",token);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.addHeader("Authorization", token)
|
||||
.get()
|
||||
.headers(hb.build())
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
public static Request postWe(OkDate od){
|
||||
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
||||
RequestBody body = RequestBody.create(mediaType,od.getMadiaType());
|
||||
Headers.Builder hb=new Headers.Builder();
|
||||
hb.add("Content-Type","application/json");
|
||||
hb.add("Cache-Control","no-cache");
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.post(body)
|
||||
.headers(hb.build())
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static Request postFile(OkDate od,String token,File file) {
|
||||
MediaType mediaType = MediaType.parse("text/plain");
|
||||
RequestBody body = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file",file.getPath(),
|
||||
RequestBody.create(MediaType.parse("application/octet-stream"), file))
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("Cookie", "JSESSIONID=NqpqKQstwceQurcNK5hjl4GnTgiF4eSzZSo5a1rz")
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static Request postFiles(OkDate od,File file,String token,String carId) {
|
||||
MediaType mediaType = MediaType.parse("text/plain");
|
||||
RequestBody body = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file",file.getPath(),RequestBody.create(MediaType.parse("application/octet-stream"), file))
|
||||
.addFormDataPart("carId",carId)
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("Cookie", "JSESSIONID=NqpqKQstwceQurcNK5hjl4GnTgiF4eSzZSo5a1rz")
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static Request postFiles(OkDate od,File file,String token,String carId,String carNum) {
|
||||
MediaType mediaType = MediaType.parse("text/plain");
|
||||
RequestBody body = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file",file.getPath(),RequestBody.create(MediaType.parse("application/octet-stream"), file))
|
||||
.addFormDataPart("carId",carId)
|
||||
.addFormDataPart("carNum",carNum)
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(od.getUrl())
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("Cookie", "JSESSIONID=NqpqKQstwceQurcNK5hjl4GnTgiF4eSzZSo5a1rz")
|
||||
.build();
|
||||
return request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MsgBean;
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.MainActivity;
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.UiAuxiliary;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.time.Timer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class RequestUtil {
|
||||
|
||||
public static final int FEEDBACK=-1;
|
||||
public static final String FEEDBACK_TEXT="请求失败,请检查网络状况";
|
||||
private static Gson gson=new Gson();
|
||||
private static MsgBean mb;
|
||||
//1执行重新请求,并更新缓存
|
||||
//2自动判断是否有缓存,如果有,不在请求
|
||||
//3自动判断是否有缓存,如果有,定时检测缓存,如果两次时间相隔超过规定时间,则也会再次请求
|
||||
public static void start(int code, final String name, Request re, Context con, final Handler hd){
|
||||
switch (code){
|
||||
case 1:a1(name,re,con,hd);break;
|
||||
case 12:a1s(name,re,con,hd);break;
|
||||
case 2:a2(name,re,con,hd);break;
|
||||
case 11:a11(name,re,con,hd);break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void start(final String name, Request re, Context con, final Handler hd, int s){
|
||||
a3(name,re,con,hd,s);
|
||||
}
|
||||
|
||||
public static void a1(final String name, Request re, Context con, final Handler hd){
|
||||
Log.e("请求开始","........");
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.build();
|
||||
client.newCall(re).enqueue( new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Log.e("请求错误","error:"+e.toString());
|
||||
Message message=new Message();
|
||||
message.obj=RequsetCodeConstants.FEEDBACK_TEXT;
|
||||
message.what=RequsetCodeConstants.ERROR;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String body=response.body().string();
|
||||
final int code=response.code();
|
||||
Log.e("e",body+"");
|
||||
//SecurityUtil.decrypt(body);
|
||||
if(body.startsWith("04")){
|
||||
body=SecurityUtil.decrypt(body);
|
||||
}
|
||||
Log.e("es",body+"");
|
||||
Message message=new Message();
|
||||
if(code==RequsetCodeConstants.SUCCESS){
|
||||
mb=gson.fromJson(body,MsgBean.class);
|
||||
if(!body.equals("")){
|
||||
if(mb.getCode()==401){
|
||||
UiAuxiliary.delLogin(con);
|
||||
Intent intent = new Intent(con, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
con.startActivity(intent);
|
||||
}else{
|
||||
CacheGroup.cacheList.put(name,body);
|
||||
message.obj=response.code();
|
||||
message.what=RequsetCodeConstants.SUCCESS;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
message.obj=response.code();
|
||||
message.what=code;
|
||||
}
|
||||
Log.e("请求响应",body);
|
||||
hd.sendMessage(message);
|
||||
//customDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void a1s(final String name, Request re, Context con, final Handler hd){
|
||||
Log.e("请求开始","........");
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.build();
|
||||
client.newCall(re).enqueue( new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Log.e("请求错误","error:"+e.toString());
|
||||
Message message=new Message();
|
||||
message.obj=RequsetCodeConstants.FEEDBACK_TEXT;
|
||||
message.what=RequsetCodeConstants.ERROR;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String body=response.body().string();
|
||||
final int code=response.code();
|
||||
Log.e("e",body+"");
|
||||
//SecurityUtil.decrypt(body);
|
||||
String bodys=body;
|
||||
Log.e("es",bodys+"");
|
||||
Message message=new Message();
|
||||
if(code==RequsetCodeConstants.SUCCESS){
|
||||
mb=gson.fromJson(bodys,MsgBean.class);
|
||||
if(!bodys.equals("")){
|
||||
if(mb.getCode()==401){
|
||||
UiAuxiliary.delLogin(con);
|
||||
final Intent intent = con.getPackageManager().getLaunchIntentForPackage(con.getPackageName());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
con.startActivity(intent);
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
Toast.makeText(con,"登陆失效",Toast.LENGTH_SHORT).show();
|
||||
}else{
|
||||
CacheGroup.cacheList.put(name,bodys);
|
||||
message.obj=response.code();
|
||||
message.what=RequsetCodeConstants.SUCCESS;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
message.obj=response.code();
|
||||
message.what=code;
|
||||
}
|
||||
Log.e("请求响应",body);
|
||||
hd.sendMessage(message);
|
||||
//customDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void a2(final String name, Request re, Context con, final Handler hd){
|
||||
//CustomDialog customDialog= new CustomDialog(con, "正在加载...");
|
||||
//customDialog.show();//显示,显示时页面不可点击,只能点击返回
|
||||
if(CacheGroup.cacheListA.get(name)==null){
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
client.newCall(re).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Message message=new Message();
|
||||
message.obj=e.toString();
|
||||
message.what=-1;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String body=response.body().string();
|
||||
//System.out.println(body);
|
||||
CacheGroup.cacheListA.put(name,body);
|
||||
Message message=new Message();
|
||||
message.what=2;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
System.out.println("已有缓存,不需要再次请求");
|
||||
Message message=new Message();
|
||||
message.what=2;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
}
|
||||
public static void a3(final String name, Request re, Context con, final Handler hd, long s){
|
||||
if(CacheGroup.cacheDateList.get(name)==null){
|
||||
//CustomDialog customDialog= new CustomDialog(con, "正在加载...");
|
||||
//customDialog.show();//显示,显示时页面不可点击,只能点击返回
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
client.newCall(re).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Message message=new Message();
|
||||
message.obj=FEEDBACK;
|
||||
message.what=-1;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String body=response.body().string();
|
||||
//System.out.println(body);
|
||||
Date d=new Date();
|
||||
CacheGroup.cacheTimeList.put(name, d);
|
||||
CacheGroup.cacheDateList.put(name, body);
|
||||
Message message=new Message();
|
||||
message.what=3;
|
||||
hd.sendMessage(message);
|
||||
//customDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}else{
|
||||
Date ds=new Date();
|
||||
System.out.println("时间差:"+ Timer.TimeD(ds,CacheGroup.cacheTimeList.get(name)));
|
||||
System.out.println("实时时间:"+s);
|
||||
if(Timer.TimeD(ds,CacheGroup.cacheTimeList.get(name))>=s){
|
||||
//CustomDialog customDialog= new CustomDialog(con, "正在加载...");
|
||||
//customDialog.show();//显示,显示时页面不可点击,只能点击返回
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
client.newCall(re).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Message message=new Message();
|
||||
message.obj=FEEDBACK;
|
||||
message.what=-1;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String body=response.body().string();
|
||||
//System.out.println(body);
|
||||
Date d=new Date();
|
||||
CacheGroup.cacheTimeList.put(name, d);
|
||||
CacheGroup.cacheDateList.put(name, body);
|
||||
Message message=new Message();
|
||||
message.what=3;
|
||||
hd.sendMessage(message);
|
||||
//customDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}else{
|
||||
System.out.println("没有超过实时缓存时间,不进行请求");
|
||||
Message message=new Message();
|
||||
message.what=3;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void a11(final String name,Request re,Context con,final Handler hd){
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
client.newCall(re).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Message message=new Message();
|
||||
message.obj=FEEDBACK;
|
||||
message.what=-1;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String body=response.body().string();
|
||||
System.out.println("存储空间"+name);
|
||||
CacheGroup.cacheList.put(name,body);
|
||||
Message message=new Message();
|
||||
message.what=1;
|
||||
hd.sendMessage(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
public class RequsetCodeConstants {
|
||||
|
||||
public static final int ERROR=-1;
|
||||
|
||||
//响应码
|
||||
//登录失效
|
||||
public static final int NOT_LOGIN=401;
|
||||
//返回成功
|
||||
public static final int SUCCESS=200;
|
||||
//请求地址找不到
|
||||
public static final int UNKONWN=404;
|
||||
//网关错误
|
||||
public static final int GATEWAY_ERROR=502;
|
||||
//服务器错误
|
||||
public static final int SERVER_ERROR=500;
|
||||
//请求的实体过大
|
||||
public static final int ENTITY_TOO_LARGE=413;
|
||||
//
|
||||
public static final String UNKONWN_TEXT="请求地址未找到";
|
||||
public static final String GATEWAY_ERROR_TEXT="网关错误";
|
||||
public static final String SERVER_ERROR_TEXT="服务器出现异常";
|
||||
public static final String ENTITY_TOO_LARGE_TEXT="上传的图片过大";
|
||||
public static final String FEEDBACK_TEXT="请求失败,请检查网络状况";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util.http;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/9/14 11:01
|
||||
* @description:
|
||||
*/
|
||||
public class SecurityUtil {
|
||||
|
||||
/**
|
||||
* 公钥
|
||||
*/
|
||||
private static final String public_key = "04B16143229EF2DF546DE8AEC5E0242E9C7B564A7D6C3D982450DAC0E46606C5851AB710059E2BBCE6D86EE2215B18274EF2642626650F9774AB57F7ADE44DF0A3";
|
||||
/**
|
||||
* 私钥
|
||||
*/
|
||||
private static final String private_key = "4993A5ED6E3F865279481A96453E4907E5943F0086EAB9C3E3B24C8A36D7CBFD";
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param data 带加密数据
|
||||
* @return 加密后的结果
|
||||
*/
|
||||
public static String encrypt(String data) {
|
||||
String str="";
|
||||
// try {
|
||||
// str=SM2Utils.encrypt132(data.getBytes(),Util.hexToByte(public_key));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param data 带加密数据
|
||||
* @return 解密后的结果
|
||||
*/
|
||||
public static String decrypt(String data) {
|
||||
byte[] bs=null;
|
||||
// try {
|
||||
// bs=SM2Utils.decrypt132(Util.hexToByte(private_key), Util.hexToByte(data));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
return new String(bs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user