pkcs1解密 springboot_SpringBoot框架中,使用过滤器进行加密解密操作(一)

importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.nio.charset.Charset;importjava.util.Base64;importorg.apache.http.HttpEntity;importorg.apache.http.HttpResponse;importorg.apache.http.HttpStatus;importorg.apache.http.client.HttpClient;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.entity.StringEntity;importorg.apache.http.impl.client.DefaultHttpClient;importorg.apache.http.util.EntityUtils;importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.boot.test.context.SpringBootTest;importorg.springframework.test.context.junit4.SpringRunner;importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONObject;importcom.lmbx.util.DES;importcom.lmbx.util.DESCoderUtil;importlombok.extern.slf4j.Slf4j;

@RunWith(SpringRunner.class)

@SpringBootTest

@Slf4jpublic classtest2 {

@Testpublic void test() throwsException {

String url="http://localhost:8080/v1/api/test";

String json="{\"placeId\":\"2\",\"mediaCode\":\"ottauto\",\"cId\":\"1\"}";

String responseBodyMw=new String(Base64.getDecoder().decode(json), "utf-8");

String doPost= doPost(url,responseBodyMw,null);

System.out.println(doPost);

}public synchronized staticJSONObject doGet(String url) {

JSONObject jsonObject=null;try{

HttpClient client= newDefaultHttpClient();

HttpGet request= newHttpGet(url);

System.out.println(request);

HttpResponse response=client.execute(request);if (response.getStatusLine().getStatusCode() ==HttpStatus.SC_OK) {

String strResult=EntityUtils.toString(response.getEntity());

System.out.println("请求结果为——》"+strResult);

jsonObject=JSON.parseObject(strResult);returnjsonObject;

}

}catch(IOException e) {

e.printStackTrace();

}returnjsonObject;

}public staticString doPost(String url,String json,String token){

DefaultHttpClient client= newDefaultHttpClient();

HttpPost post= newHttpPost(url);

String response= null;try{

StringEntity s= new StringEntity(json,Charset.forName("UTF-8"));

s.setContentEncoding("UTF-8");

s.setContentType("application/json");//发送json数据需要设置contentType

post.setEntity(s);

post.setHeader("token", token);

post.setHeader("Content-Type", "application/json; charset=UTF-8");

HttpResponse res=client.execute(post);if(res.getStatusLine().getStatusCode() ==HttpStatus.SC_OK){

HttpEntity httpEntity=res.getEntity();

BufferedReader reader= null;

reader= new BufferedReader(new InputStreamReader(httpEntity.getContent(), "UTF-8"), 10 * 1024);

StringBuilder strBuilder= newStringBuilder();

String line= null;while ((line = reader.readLine()) != null) {

strBuilder.append(line);

}

response=strBuilder.toString();

}

}catch(Exception e) {throw newRuntimeException(e);

}returnresponse;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值