2015-01-07 16 views
5

Benim app indirilen dosyalar için bir şifreleme/şifre çözme mekanizması var.Android lolipop şifrelenmiş dosya şifresini çözemez

Bu mekanizma 5.0-lolipop android önce tüm android cihazlar ve sürümlerinde çalışır. Burada

şifre çözme yöntemidir: şifre ve anahtar daha önce oluşturulan ve bütün uygulama kullanılan
cipher.init(Cipher.DECRYPT_MODE, key); 
fileInputStream = new FileInputStream(file); 
cipherInputStream = new CipherInputStream(fileInputStream, cipher); 
byte[] fileByte = new byte[(int) file.length()]; 
int j = cipherInputStream.read(fileByte); 
return fileByte; 

:

key = new SecretKeySpec(keyValue, "AES"); 
try { 
    cipher = Cipher.getInstance("AES"); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

I robot 5.0, j yaklaşık 200,000 bayt ile bir dosya şifresini zaman (dönüş öncesi değişken) 200000'den daha düşük olan yaklaşık 8000'tir, eski android sürümlerinde ise şifrelenmiş dosya uzunluğuna eşittir.

Sorunun şifre çözme işleminde olduğunu buldum. Çünkü bir dosyayı android 5.0'da şifreleyebilir ve eski android sürümlerinde şifresini çözebilirim, fakat tersini değil. Ancak I am posta şifreleme işlemi: önceden

cipher.init(Cipher.ENCRYPT_MODE, AESutil.key); 
cipherOutputStream = new CipherOutputStream(output, cipher); 
byte data[] = new byte[1024]; 
int count; 
while ((count = input.read(data)) != -1) { 
    cipherOutputStream.write(data, 0, count); 
} 

Teşekkür

+0

Akışınız benim Aplikasyon dizine String kullanım bana oldukça korkak gözüküyor. Dosyanın büyüklüğünde bir arabellek oluşturmak tüm bu baytların gerçekten okunacağı anlamına gelmez. Ve şifreleme sırasında akışı açıkça kapatmıyor gibi görünüyorsunuz (ama belki de dahil değildir). –

+0

@ MaartenBodewes-owlstead Evet Onları kapattım. Sorun hala var. –

+0

Doğru bayt miktarının da, j' = -1 olana kadar baytları okuyarak okunabildiğinden emin misiniz? –

cevap

2

Benim Şifreleme örneği (L):

AppPath sd kart

static void encrypt(File file, String pass) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { 


     FileInputStream fis = new FileInputStream(file); 


     FileOutputStream fos = new FileOutputStream(APPPATH+"/E_"+file.getName()); 


     SecretKeySpec sks = new SecretKeySpec(pass.getBytes(), "AES"); 

     Cipher cipher = Cipher.getInstance("AES"); 
     cipher.init(Cipher.ENCRYPT_MODE, sks); 

     CipherOutputStream cos = new CipherOutputStream(fos, cipher); 

     int b; 
     byte[] d = new byte[8]; 
     while((b = fis.read(d)) != -1) { 
      cos.write(d, 0, b); 
     } 

     cos.flush(); 
     cos.close(); 
     fis.close(); 


    } 



    static void decrypt(File file, String pass) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { 

      FileInputStream fis = new FileInputStream(file); 

      FileOutputStream fos = new FileOutputStream(APPPATH+"/D_"+file.getName()); 
      SecretKeySpec sks = new SecretKeySpec(pass.getBytes(), "AES"); 
      Cipher cipher = Cipher.getInstance("AES"); 
      cipher.init(Cipher.DECRYPT_MODE, sks); 
      CipherInputStream cis = new CipherInputStream(fis, cipher); 
      int b; 
      byte[] d = new byte[8]; 
      while((b = cis.read(d)) != -1) { 
       fos.write(d, 0, b); 
      } 
      fos.flush(); 
      fos.close(); 
      cis.close(); 
     } 
+0

Teşekkürler Michal. Şuan çalışıyor! :-) –

İlgili konular