Android encryption/decryption issue (AES)

蹲街弑〆低调 提交于 2019-12-03 08:29:37

About loading the encrypted image: You can use the /assets folder, is in your workspace at the same level than /res. Then you place the file inside. Let's say it is called "myfile.enc". You should use the AssetManager to retrieve the file:

    AssetManager am = activity.getAssets();
    InputStream is = am.open("myfile.enc");

With the InputStream, you can write it to a ByteArrayOutputStream and then get the bytes, or you could pass it to a CipherInputstream instead of calling Cipher.doFinal. This is the way to go if you have a relatively large resource. But for your little test, I think the byte version is the easiest.

To get the Bitmap thing working, I would also put it under assets folder and then get the bytes with the same procedure. The drawables folder is generally for images you are going to use in the GUI, so you can use their ID's on R.java.

Two things:

-You are performing an extensive task on the Ui Thread (AKA event thread). This is very bad way of doing things, because you are blocking the GUI, and if you spend too much time on it, the OS will launch the "Application not responding" error.

-I think you are not launching a View in the onCreate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!