【发布时间】:2022-01-23 11:34:52
【问题描述】:
在我的应用程序中,我使用的是使用 Retrofit 的 Web 服务。我必须在请求中加密字段(参数)并在 PHP 服务器上对其进行解密。
我必须加密和解密版本参数。
这是我的 RetroApi.java
公共接口 RetroApi {
@FormUrlEncoded
@POST("index.php/api/check-version")
Call<String> getCheckVersion(@Field("version") String version, @Field("app") String app);
}
创建 RetroApi.java 的实例
RetroApi retroApi;
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder().addInterceptor(logging).build();
Gson gson = new GsonBuilder().setLenient().create();
Retrofit retrofit = new Retrofit.Builder().baseUrl(RetroApp.BASE_URL).addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient).build();
retroApi = retrofit.create(RetroApi.class);
这是 Web 服务调用
Call<String> getResult = retroApi.getCheckVersion(Constants.SP_APP_VERSION, Constants.SP_APP_NAME);
getResult.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
}
@Override
public void onFailure(Call<String> call, Throwable t) {
t.printStackTrace();
}
});
请帮助我完成这项工作。
【问题讨论】:
-
你遇到了什么问题?
-
@AbuYousuf 我必须加密响应并在服务器上解密
-
Encrypt the response或Encrypt the api parameters? -
加密api参数
-
Encrypt the api parameters遇到什么问题?
标签: android encryption retrofit2 sha256