Android AES-128 encryption/decryption of file is very slow. How can I increase the speed

前端 未结 2 2048
遇见更好的自我
遇见更好的自我 2021-02-03 15:29

I am developing an android app that secures images and videos like Vaulty and Keep safe. I am trying to use AES-128 encryption/decryption technique to store images and videos. I

相关标签:
2条回答
  • 2021-02-03 15:40

    One thing that is making your code run slow is the size of your buffer:

    byte[] d = new byte[8];
    

    You should bump it up by a few orders of magnitude if you want it to run fast. Given the size of your files I would suggest using at least 1 MB but nowadays you can realistically set it to a few MBs, even on Android. Try changing it to:

    byte[] d = new byte[1024 * 1024];
    

    and let us know how much did that improve the speed by.

    0 讨论(0)
  • 2021-02-03 15:48

    Use a larger buffer as suggested by @MikeLaren, and also wrap the FileOutputStream in a BufferedOutputStream. When decrypting, wrap the FileInputStream in a BufferedInputStream. Or do both in both cases: no harm done.

    No need for heroic buffer sizes like a megabyte: 8k or 32k is sufficient.

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