How would I go about playing a set of encrypted audio files in a audio player android app?
I have an app project where I would have a set of encrypted audio content stored on a users device. A single audio content (example: podcast) would in this case consist of multiple encrypted files. The app acts as a audio player, through which users listen to this audio content.
For good user experience the whole content (podcast) should play seamlessly from one file to another. This works perfectly for normal audio files using android's MediaPlayer class.
For security measures, no decrypted file should at any point be present on the users device storage in a way that a user can access this file any other way than through my app (even on rooted devices).
The type of encryption to be used is not fixed yet, so I am open to any algorithm that would work best for this case.
I thought about decrypting each file before playing it. Files are a maximum of 25MB in size, and a AES encryption/decryption for such file takes some 300 milliseconds, so this does not disturb the user experience too much.
There are two problems I see here with two different approaches to decryption:
The simples way, IMO, is to use
ExoPlayer, which is an open-source media player developed by Google. They dealt on this project with lots of edge cases and it's a nice and reliable player.
On top of that your needs are easy to achieve pretty much out-of-the-box.
You'll just load your player using a
AesCipherDataSource wrapping a
So your file is encryped locally using AesCihper and decrypted on the fly, chunk by chunk by the player itself.
Here is the link to their dev-guide: https://google.github.io/ExoPlayer/guide.html and to the AesCipher http://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSource.html