Using Android NDK for encryption of data passed from normal android app

shtolik picture shtolik · Feb 16, 2011 · Viewed 8.3k times · Source

Is it possible and worth trying to develop some server application using android NDK which will encrypt data (or just use some built in Linux encryption library) passed to it from normal Java based application?

I tried using Cipher library, but it took almost a minute to encrypt 2MB file with AES. And blowfish is not available in Cipher until Android 2.3(?). And I doubt it will be much faster.

I was using blowfish for encryption on Symbian and it was much faster (under 5-10 seconds) so I think in android it is slower because of using Java virtual machine and I'd like to try native app for it.

Have someone done it before?

EDIT: Encrypting in NDK is so much faster. Do it there. There is a similar question with the same answer for AES: AES decryption on Android too slow to be usable. Will NDK be faster? Other ideas?

Answer

sabalab picture sabalab · Jul 22, 2011

BouncyCastle in Android 2.2 is horribly slow with AES/CBC/PKCS5 while using stream decryption. CPU is going to 100% and throughput is 5kb/sec.

Using Chilkat is magnitudes faster and keeps CPU usage low (even in the Emulator). But Chilkat is not offering an InputStream to handle stream decryption and is buffering all the encrypted bytes internally (until a heap space error occurs). So you must manage stream decryption yourself (e.g. by initializing chilkat for every block...)