Kiran Panesar
Kiran Panesar

Reputation: 3204

How to Encrypt mp3 Files in iOS

I have an app that downloads MP3 files from our web server and momentarily stores them in an NSData object. This object is then written to a .mp3 file stored to the /Library/Cache folder in the app's sandbox.

When it is time to play the file, I load it into an AVPlayerItem like so:

    NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
                          stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3", trackID]];

    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    self.trackPlayerItem = [[AVPlayerItem alloc] initWithURL:fileURL];

I think proceed to load this item into an AVPlayer and play it.

So my main question is: How do I encrypt these mp3 files while they're stored on the disk to ensure they can't just be plucked from the file system by anyone with a Jailbroken device?

I've already looked on Stack Overflow but couldn't find anything that helped.

Hope someone can help me out. Thanks

Upvotes: 0

Views: 2328

Answers (1)

Iñigo Beitia
Iñigo Beitia

Reputation: 6353

Check out this thread on adding RSA encryption/decryption to NSData.

Upvotes: 2

Related Questions