gpt4 book ai didi

java - 在 Rest Web 服务中发送 url 作为查询参数

转载 作者:行者123 更新时间:2023-12-02 00:58:56 25 4
gpt4 key购买 nike

我编写了一个 REST 服务来加密和解密 URL。

加密代码:

@GET
@Produces("application/json")
@Path("/encrypt/")
public Response encryptWithQuery(@QueryParam("plainString") String plainString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.encrypt(SALT, IV, PASSPHRASE, plainString);
return response;
}

解密代码:

@GET
@Produces("application/json")
@Path("/decryptWP/")
public Response decryptWithQuery(@QueryParam("encryptString") String encryptString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.decrypt(SALT, IV, PASSPHRASE, encryptString);
return response;
}

当我调用加密休息服务时,我得到加密的字符串

加密 URL

http://localhost:9080/kttafm/keybank/encrypt?plainString=http://localhost:9080/kttafm/master.jsp?abc=zyx

但是当我调用解密休息服务时,我遇到了以下异常

javax.crypto.BadPaddingException: Given final block not properly padded

但是如果我从 @Queryparam tp @path param 移动,解密工作正常,

可以正常工作并解密加密字符串的解密方法是

 @GET
@Produces("application/json")
@Path("/decrypt/{encryptString}")
public Response decrypt(@PathParam("encryptString") String encryptString)
throws JSONException {
Response response = new Response();
AesUtil util = new AesUtil(KEY_SIZE, ITERATION_COUNT);
response = util.decrypt(SALT, IV, PASSPHRASE, encryptString);
return response;
}

我错过了什么?

最佳答案

请确保您始终 encode客户端的参数,例如使用URLEncoder.

例如,您的加密 URL 必须是

http://localhost:9080/kttafm/keybank/encrypt?plainString=http%3A%2F%2Flocalhost%3A9080%2Fkttafm%2Fmaster.jsp%3Fabc%3Dzyx

关于java - 在 Rest Web 服务中发送 url 作为查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33140886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com