Slow AES decryption in Android

前端 未结 2 1435
清酒与你
清酒与你 2020-12-14 05:11

I tried to decrypt a 4.2 MB .dcf file using AES 128 bit key, but it took 33 seconds to decrypt (on function cipher.doFinal(data)), is it normal ?

Here is a code snip

相关标签:
2条回答
  • 2020-12-14 05:29

    AFAIK, there's no way to get access to the ARM chip's AES encryption/decryption hardware via the Android APIs :-(

    This is a huge oversight on Google's part unfortunately...makes using AES on other platforms a LOT faster....

    0 讨论(0)
  • 2020-12-14 05:38

    You should try to bench the time taken without the file writing, i.e. call System.currentTimeMillis() right before and right after the call to cipher.doFinal().

    That being said, an Android-based phone typically uses a recent ARM processor clocked at 500 MHz or more, and such a beast is theoretically able to AES-encrypt or AES-decrypt several megabytes worth of data per second.

    However, Android code uses an almost-Java virtual machine called Dalvik. Prior to Android-2.2, this is an interpreter (no JIT compiler), which means that it is kinda slow for computing-intensive tasks. If the mediocre performance you observe really comes from the AES operation itself (and not the file writing) then the plausible answer is that your VM provides an AES implementation that is written in Java and interpreted with Dalvik. In that case, there is little cure except hoping for the presence of a better VM implementation (a VM could use a native code implementation for AES; also, with Android 2.2 and later, Dalvik has a JIT compiler which should boost performance of code execution).

    0 讨论(0)
提交回复
热议问题