2011-02-15 28 views
0

增長速度,我不知道這是可能的...我有我的應用程序,加密圖像中的代碼...的Android - 加密

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(); 
    } 

我每次加密或解密的圖像(這我應用程序確實需要很長時間,有關如何增加過程的任何提示,以便用戶有更好的體驗?

回答

3

如果您願意爲速度交易一點安全性,那麼您只能對圖片的特定部分進行加密:例如,每1000個字節的數據流中有前100個字節。

另外,使用AsysTask,@Estel建議,這樣你的用戶界面不會受到延遲。

1

我最好的建議是增加緩衝

1

如果您的用戶體驗是痛苦的大小,你把這個加密算法在的AsyncTask?對於像這樣昂貴的操作,需要一個ASyncTask來保持用戶體驗的順暢。

2

您可能會選擇不同於ECB的AES模式。不僅速度快,而且還要比ECB的加密圖像做better job

+0

其它模式均優於歐洲央行很多事情,但他們都沒有任何更快。 – 2011-02-15 12:34:58

+0

它可以依賴於框架,例如:http://www.cryptopp.com/benchmarks.html – 2011-02-15 12:48:20

0
  1. 使用更大的緩衝區
  2. 使用的AsyncTask。你甚至可以在通知欄中顯示用戶進度,這應該讓他開心。
  3. 使用NDK本地代碼寫加密