Encryption while disk caching - android

So what I to achieve is to apply encryption while caching images on disk.
I have decided to go with Universal Image Loader, I understand I will have to add an custom
disk caching implementation of my own but I don't know where to start with.
How can I achieve this, encryption while writing byte stream in file and decryption while getting the stream only from file.
Any kind of help would be deeply appreciated :)

Thanks for not replying :P
But I did eventually end up solving it. And here is what I did, maybe It will help anyone else.
All I had to was to create a custom disk cache and custom downloader.
In custom disk caching class, in the method where UIL write byte stream to file, I encrypted the byte stream.
and In custom downloader, I override the method where it take byte stream from file and decrypted it.

Related

Processing a file with Oboe

I'd like to build something a little like the LiveEffect sample in the Google/Oboe library.
However, I want to affect the audio selected from a file chosen by the user rather than the microphone input. I do not need the input.
There's no example in the Google/Oboe repo of how to operate on a file.
Does anyone have an example or guidance so I can let the user choose a file from their local storage, then (and this is the bit I'm missing) pass the audio across the JNI bridge to my oboe app?
I do the need low-latency capability of Oboe as I'm going to affect the audio in response to motion data.
Any guidance gratefully recieved.
For anyone passing by in search of a similar solution, here's how I solved this
On the Java/Kotlin side pick up the audio file (i used a WAV in this
case) with an intent
Use a contentResolver on the audio file to create an inputStream
read the data from the inputStream into a byteArray
pass the byteArray over the JNI bridge to the native code
wrap the byteArray in a MemInputStream from the PARSELIB example
wrap the MemInputStream in a WavStreamReader, also from the PARSELIB example
create a SampleBuffer, from the IOLIB example, and load the WavStreamReader into it
create SampleSource, from the IOLIB example, and give it the SampleBuffer
give the SampleSource and SampleBuffer to the SimplePlayer from the IOLIB example
do the processing in the SampleSource's mixAudio() method bearing in mind all the rules for real-time processing in Oboe.
I also needed to do this on the block because I have a fixed window operation. to do this, I adapted the SampleBuffer class to add a method that would pull block data into mixAudio(), but that's only specific to some cases.
I hope that helps someone in the future.

DiskCache encryption and decryption of Glide Images?

How to encrypt and decrypt disk cache images in android using Glide ?
Hi one idea would be create a cache decoder / encoder and use a library such https://github.com/facebook/conceal to do the hard encrypt / decrypt lift.
This image might help you navigate through the life cycle of glide:

Android fresco how to get save cache callback?

I got a question about android fresco library. Do you guys know how to get callback when file is saved in cache? Generally, we could get file from cache:
ImageRequest imageRequest= ImageRequest.fromUri(url);
CacheKey cacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file=((FileBinaryResource)resource).getFile();
However, if I put this in onCreate() function, it will crash since the file was not in the cache yet. Do you guys know how I got get a callback when the fresco finish saving it? Is it DataSubscriber? Could you guys provide an example? I read the documentation but I couldn't figure out.
Thanks.
I am part of the Fresco team and may be able to help. Please see our documentation on how to properly get the encoded image bytes. There is a code example of how to get an InputStream of the encoded image (which is what is being stored in cache). You can then use those bytes directly, or if you need a File in order to pass it somewhere else, you should create your own file and store the returned bytes in it. There is no other safe way to deal with cached images because you have no guarantees that Fresco will not evict (delete) the cached file at any time.

Picasso load image into GifImageView (android-gif-drawable library)

I am using the android-gif-drawable library to display an animated gif in an Android view. This library can load a file from an input stream, byte array, byte buffer, or from a locally stored file. I am looking for a way to use Picasso to download the gif and pass it to the library to load into the GifImageView. Unfortunately, once the downloaded image is converted to a Bitmap, it just becomes a single frame. I'm thinking a custom request handler might be able to hand off an input stream for the GifImageView to load, but I cannot seem to figure out the syntax to do this. Does anyone have pointers or thoughts on doing this?
If you haven't figured it out yet, you can use the library Ion. I was facing the same problem a few days ago, and it worked for me.

Encryption in disk caching Picasso android

I am planning on implementing, Picasso with OKHTTP for Disk caching of images. But I also plan on having encryption on images caches on disk. What should I do? I couldn't find a single helpful link, that can guide me in the right direction. Any kind of help would be greatly appreciated.
If somebody is looking for an answer, here is how I achieved it.
Firstly I switched to UIL since it provides more customization than Picasso.
Then I customized the built in diskCache mechanism.
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(getApplicationContext());
builder.threadPriority(Thread.NORM_PRIORITY - 2);
builder.threadPoolSize(5);
builder.imageDownloader(new CustomImageDownaloder(this, new OkHttpClient()));
builder.diskCache(new CustomDiskCache(cacheDir));
Now in CustomDiskCache just override the methods where it read bytes from network and save them to disk, read bytes encrypt them and save them. Similarly, when you are about to read from cache file, decrypt bytes and convert them to bitmap.
Hope it helps.

Categories

Resources