我在哪里放置用于在改造 android 中响应的解密代码
Where i put decryption code for responce in retrofit andriod
我想解密服务器数据 我可以在 android 中使用改装
在哪里解密它
在使用 enc/dec 之前,我从服务器
获取了这些数据
{
"success": true,
"secret": "NVARWBA4MAGSAW2F"
}
当我点击这个API
@Headers("Content-Type: application/json")
@POST("user")
suspend fun addUser(@Body addUser: AddUser): Response<com.pryze.repository.model.User>
并且在使用 enc/dec 仅响应服务器后,我得到了加密文本
'JAdS9hy168A2fG6FVTyzmFY739iawyk9qZ/yynRLtFTtE9nXxHyEas5ZrLzpl9IhpdgD27RpPBS5HsFHnVParg=='
我的应用程序由于非法响应而崩溃我该如何解决这个问题,我可以将我的 dec 代码先解密然后将其分配给响应。
请在您的检查器 class 中尝试使用此代码进行加密和解密。
override fun intercept(chain: Interceptor.Chain): Response {
if (!isInternetAvailable()){
throw NoInternetException("Make sure you have an active data connection")
}
try {
val aesUtil = AesUtil(keySize, iterationCount)
var request: Request = chain.request()
val buffer = Buffer()
request.body?.writeTo(buffer)
val strOldBody: String = buffer.readUtf8()
val encText = aesUtil.encrypt(salt,iv,passphrase,strOldBody)
val mediaType: MediaType? = "text/plain; charset=utf-8".toMediaTypeOrNull()
val strNewBody: String = encText
val body: RequestBody = RequestBody.create(mediaType, strNewBody)
request = request.newBuilder().addHeader("authorization", "Bearer " + t.getToken("JWT")).header("Content-Length", body.contentLength().toString()).method(request.method, body).build()
var req= chain.proceed(request)
var enc_data=""+req.body?.string().toString()
enc_data = aesUtil.decrypt(salt,iv,passphrase,enc_data)
return req.newBuilder().body(ResponseBody.create(req.body?.contentType(), enc_data)).build()
}
catch (e:ServiceConfigurationError){
}
catch (e: SSLHandshakeException){
throw NoInternetException("Request Time Out")
}
catch (e: ConnectException){
throw NoInternetException("Request Time Out")
}
catch (e: SocketTimeoutException){
throw NoInternetException("Make sure you have an active data connection")
}
catch (e:UnknownHostException){
throw NoInternetException("Make sure you have an active data connection")
}
catch (e: ErrnoException){
throw NoInternetException("Request Time Out")
}
throw NoInternetException("Request Time Out")
}
我想解密服务器数据 我可以在 android 中使用改装
在哪里解密它在使用 enc/dec 之前,我从服务器
获取了这些数据{
"success": true,
"secret": "NVARWBA4MAGSAW2F"
}
当我点击这个API
@Headers("Content-Type: application/json")
@POST("user")
suspend fun addUser(@Body addUser: AddUser): Response<com.pryze.repository.model.User>
并且在使用 enc/dec 仅响应服务器后,我得到了加密文本
'JAdS9hy168A2fG6FVTyzmFY739iawyk9qZ/yynRLtFTtE9nXxHyEas5ZrLzpl9IhpdgD27RpPBS5HsFHnVParg=='
我的应用程序由于非法响应而崩溃我该如何解决这个问题,我可以将我的 dec 代码先解密然后将其分配给响应。
请在您的检查器 class 中尝试使用此代码进行加密和解密。
override fun intercept(chain: Interceptor.Chain): Response {
if (!isInternetAvailable()){
throw NoInternetException("Make sure you have an active data connection")
}
try {
val aesUtil = AesUtil(keySize, iterationCount)
var request: Request = chain.request()
val buffer = Buffer()
request.body?.writeTo(buffer)
val strOldBody: String = buffer.readUtf8()
val encText = aesUtil.encrypt(salt,iv,passphrase,strOldBody)
val mediaType: MediaType? = "text/plain; charset=utf-8".toMediaTypeOrNull()
val strNewBody: String = encText
val body: RequestBody = RequestBody.create(mediaType, strNewBody)
request = request.newBuilder().addHeader("authorization", "Bearer " + t.getToken("JWT")).header("Content-Length", body.contentLength().toString()).method(request.method, body).build()
var req= chain.proceed(request)
var enc_data=""+req.body?.string().toString()
enc_data = aesUtil.decrypt(salt,iv,passphrase,enc_data)
return req.newBuilder().body(ResponseBody.create(req.body?.contentType(), enc_data)).build()
}
catch (e:ServiceConfigurationError){
}
catch (e: SSLHandshakeException){
throw NoInternetException("Request Time Out")
}
catch (e: ConnectException){
throw NoInternetException("Request Time Out")
}
catch (e: SocketTimeoutException){
throw NoInternetException("Make sure you have an active data connection")
}
catch (e:UnknownHostException){
throw NoInternetException("Make sure you have an active data connection")
}
catch (e: ErrnoException){
throw NoInternetException("Request Time Out")
}
throw NoInternetException("Request Time Out")
}