English 中文(简体)
如何在吉勒吉大港山区客户中进行加密和使用加密反应
原标题:How to Decrypt and Use Encrypted Response in Ktor HTTP Client

Im在安乐器应用方面工作,我需要将申请机构加密,然后再将其发送服务器,然后对从服务器收到的答复进行加密。 使用Ktor s HTTP客户进行网络申请的Im,我有CryptoUtils级,使用AES处理加密和加密。 在此概述我所做的工作:

  1. Encryption: I have successfully installed a plugin to encrypt the request body before it s sent to the server. Here s the code for the encryption install (this exemple is for login only, i willl make it global later):
private fun HttpClientConfig<OkHttpConfig>.encryptionInstall() {
    install("EncryptRequest") {
        requestPipeline.intercept(HttpRequestPipeline.Transform) { request ->
            if (request !is EmptyContent) {
                val request = request as LoginDTO
                val originalBody = Json.encodeToString(x)
                val encryptionKey = "MY_ENCRYPTION_KEY"
                val encryptedBody = CryptoUtils.encryptData(
                    encryptionKey, originalBody
                )
                val encryptedContent = TextContent(encryptedBody, ContentType.Application.Json)
                proceedWith(encryptedContent)
            } else {
                proceedWith(request)
            }
        }
    }
}
    

2. 加密: 现在,Im试图通过对从服务器收到的答复进行加密。 此处为加密装置代码:

private fun HttpClientConfig<OkHttpConfig>.decryptInstall() {
    install("DecryptResponse") {
        receivePipeline.intercept(HttpReceivePipeline.After) { response ->
            val originalResponseReceived = response.body<String>()
            runCatching {
                val encryptionKey = "MY_DECRYPTION_KEY"
                val decryptData = CryptoUtils.decryptData(
                    encryptionKey, originalResponseReceived.toString().replace("
", "")
                )
                val castedFromStringToObject =
                    Json.decodeFromString<LoginResponseDTO>(decryptData.orEmpty())
                // Now I have the decrypted data, how do I proceed with it?
                // I need to create an HttpResponse object with this decrypted data.
                // But I can t create an instance of an abstract class HttpResponse.
                // How can I create a new HttpResponse to proceed with the decrypted data?
            }
        }
    }
}

我尝试利用DecodeResponse plugin对回复进行加密,我成功地对内容进行了加密。 然而,在试图处理加密数据时,我遇到了一个问题。 自2006年以来 HttpResponse是一个抽象的类别,我无法直接创立一个处理加密数据的例子。

我期望能够建立一个带有加密数据的新HttpResponse物体,以便我能够继续处理。 然而,由于HttpResponse是抽象的,我不清楚如何着手。 我需要就如何建立新的HttpResponse提供指导或实例,以便在加密后处理加密数据。

任何关于如何实现这一目标的见解或实例都会受到高度赞赏。

事先感谢你的帮助!

问题回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...