Using Android NDK to encrypt data transferred from a regular Android application

Is it possible and worth trying to develop some kind of server application using the Android NDK that will encrypt data (or just use some built-in Linux library libraries) transferred to it from a regular Java-based application?

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

I used blowfish to encrypt on Symbian, and it was much faster (less than 5-10 seconds), so I think that in android it is slower due to the use of the Java virtual machine, and I would like to try my own application for it.

Has anyone done this before?

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

+7
source share
5 answers

What version of Android are you testing? Keep in mind that starting with Froyo, there is a tracer JIT that should work well for loops with intensive mathematical computation in the cryptographic library.

For older versions, you probably want to do this with the NDK, yes. I donโ€™t know why you need a server - just compile any good / fast cryptographic library and create a wrapper around it using the NDK. Then you can simply use the shell from your Java application.

+1
source

BouncyCastle in Android 2.2 is terribly slow with AES / CBC / PKCS5 when using stream decryption. The CPU will be 100% and the throughput will be 5 kbps.

Using Chilkat is faster and reduces CPU consumption (even in the emulator). But Chilkat does not offer an InputStream to handle decryption of the stream and buffers all encrypted bytes inside (until an error occurs in the heap area). Therefore, you must manage the decryption of the stream yourself (for example, by initializing chilkat for each block ...)

+2
source

To answer your question, yes, you could probably write something that will work with NDK, but I don't understand why you need it.

If you just want to encrypt the data that is in the sql repository, you can check SQLCipher ( https://guardianproject.info/code/sqlcipher/ )

You might also try using some annoying lock libraries ( http://www.bouncycastle.org/java.html ). They may be faster than those built into orroid, or they may have a blowfish library that you can use.

+1
source

This is not open source, but in terms of Chillkat performance , the best I have found.

0
source

Of course, you can use an external library for encryption. You can use openssl, for example https://github.com/guardianproject/openssl-android . The only question is how significant will be the influence of the JNI level that exists between Java and C code. If you need to transfer a lot of dates to C and vice versa, then you will get the opportunity to change the source library with a JNI layer. It would be much better to port more functionality from Java to C so that the data that needs to be encrypted can only be processed in C. For example, the network stack and encryption can be in C, and the user interface in Java. This is just an offer that you should know better if this is possible or not.

0
source

All Articles