我不知道这是可能的......我有在我的应用程序code的加密图像...
I am not sure if this is possible...i have code within my application which encrypts images...
Cipher cipher;
SecretKey key;
byte[] buf = new byte[1024];
DesEncrypter() {
byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
key = new SecretKeySpec(iv, "AES");
try {
cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, key);
}
catch (NoSuchProviderException e) {}
}
public void encrypt(InputStream in, OutputStream out) {
try {
out = new CipherOutputStream(out, cipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
}
我每次加密或解密的图像(其中我的应用程序很多),它需要一个很长的时间,如何提高的过程中,使用户获得更好的体验任何提示?
Every time i encrypt or decrypt an image (which my application does alot) it takes a very long time, any tips on how to increase the process so users have a better experience?
如果你愿意换一个位安全的速度,比你只能加密图像的特定部分,例如:前100个字节,每1000字节的数据流。
If you are willing to trade a bit of security for speed, than you could only encrypt specific parts of the picture: for example first 100 bytes out of every 1000 bytes of datastream.
此外,使用的AsyncTask,作为@Estel建议,让你的UI将不会受到延误。
Also, use AsyncTask, as @Estel suggested, so that your UI won't suffer delays.