# android

Souhail Marghabi

04/04/2020, 8:32 AM
Greetings, I am not sure if it is the right if it is the right channel, but I do hope some guidance and/or help. I have recently starting Using Glide to load Images from a REST API for a new project I am working and I have become somewhat desperate with an issue I am facing at the moment. I am trying to load images from an existing API, the issue is that the images come as encrypted Bytearray and cannot be read if not decrypted prior to being loaded to the imageView. The flow is as follows: LoadImage(id) -> OutputByteArray -> DecryptAES() -> assign decrypted bytearray/bitmap to imageView. I tried to look for tutorials and examples in Kotlin to do this step, but could not find any relevant sources(I am aware of ModelLoaders and DataRetrievers), but I could not understand how I could add that simple step of Decryption step through Glide
Copy code
// RecyclerViewListItem.kt

val encryptedImageEndpoint = "API_URL"
  val glideUrl = GlideUrl(encryptedImageEndpoint) { mapOf(Pair("Authorization", "Bearer $testToken")) }
               .apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).skipMemoryCache(true).override(selfReference.snapshotImage.width, selfReference.snapshotImage.height)

//before loading to imageVIiew I need the following to be done with the API Call response: val decryptedByteArray = CryptoCbc.decryptAesCBC(byteArrayFromResponse, sharedSecret)


04/04/2020, 12:45 PM
Glide will happily use OkHttp to make its network requests - we’ve used that many times when we had to provide authentication headers when loading images - see Given that OkHttp lets you intercept and rewrite both requests and responses - I believe you could move the decryption step into an OkHttp interceptor and manipulate the byte array before Glide ever sees it or tries to push it into a view.

Souhail Marghabi

04/06/2020, 2:19 PM
Thanks, i will check it out.