ak93 ak93 - 1 year ago 232
Android Question

Android encrypted audio player

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:

  1. If I decrypt a file and store it on device as a normal audio file, the user will be able to get to it (rooted devices) and use it outside my app.

  2. If I decrypt a file and keep it in system memory as lets say a byte array, how do I play this back to the user? I have found no way to do this using MediaPlayer, or have found any other library that would allow this out of the box. Maybe some audio streaming library could be modified to play out of a decrypted file stream?

Answer Source

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 FileDataSource.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download