Slow decryption of AES in Android

I tried to decrypt a file with a file size of 4.2 MB using an AES key of 128 bits, but it took 33 seconds to decrypt (using the cipher.doFinal (data) function), is this normal?

Here is the code snippet:

long start = System.currentTimeMillis()/1000L; try { SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec); android.util.Log.d("TEST", "Start decoding...." + String.valueOf(length)); byte[] decrypted = cipher.doFinal(content); File file2 = new File(Environment.getExternalStorageDirectory().getPath() + "/test.mp3"); OutputStream os = new FileOutputStream(file2); os.write(decrypted); } catch (Exception ex) { ex.printStackTrace(); } long end = System.currentTimeMillis()/1000L; android.util.Log.d("TEST","Time "+ String.valueOf(end-start)); 
+6
android encryption aes
source share
2 answers

You should try to estimate the time taken to write the file, i.e. call System.currentTimeMillis() right before and immediately after calling cipher.doFinal() .

Thus, an Android phone usually uses a recent ARM processor with a clock frequency of 500 MHz or more, and such a beast is theoretically capable of encrypting AES or AES-decrypting several megabytes of data per second.

However, the Android code uses an almost Java virtual machine called Dalvik . Prior to Android 2.2, this is an interpreter (not a JIT compiler), which means that it is rather slow for tasks with intensive computation. If the mediocre performance you observe really comes from the AES operation itself (and not the file write), then the plausible answer is that your virtual machine provides an AES implementation written in Java and interpreted using Dalvik. In this case, there are few cures, besides the hope of having a better implementation of the virtual machine (VM can use the built-in code implementation for AES, and also with Android 2.2 and later versions, Dalvik has a JIT compiler that should improve code execution performance).

+2
source share

AFAIK, there is no way to access the encryption / decryption device of the AES ARM chip via the Android API: - (

This is a huge control over part of Google, unfortunately ... makes using AES on other platforms much faster ....

0
source share

All Articles