user2533039
user2533039

Reputation: 15

Android AES/CBC encryption

Currently I'm using AES/CBC encryption using the javax.crypto.cipher library, however, I'm finding its a little too slow. It takes anywhere between 45s-1m to decrypt a 10 minute .mp4 video file.

Is there a better way to do this on Android? I'm looking around and found some posts about openssl but is it really that much faster?

Any links, helpful posts and/or comments would be greatly appreciated.

Upvotes: 0

Views: 573

Answers (2)

libeasy
libeasy

Reputation: 381

Willing to decrypt the entire video before to start playing exposes the user to a noticeable delay. You should consider a streaming architecture.

A typical design involves the javax.crypto.CipherInputStream class and a local http instance. There is no class for an http server in the SDK, you have to implement your own or look for an existing library similar to LocalSingleHttpServer.

It looks like:

mServer = new LocalSingleHttpServer();
mServer.setCipher(myGetCipher());
mServer.start();
path = mServer.getURL(path);
mVideoView.setVideoPath(path);
mVideoView.start();

Upvotes: 0

Maarten Bodewes
Maarten Bodewes

Reputation: 94058

Use streaming instead of file decryption. If you stream the video you can simply perform the decryption of the video as you need it. If you use CTR or CBC mode you can even skip to a specific place within the stream, although it will take some additional tricks to make that happen.

Leaving decryption to the default provider should be first choice, but you can certainly speed up things using a native decryption library.

Upvotes: 1

Related Questions