i've encrypted , decrypted 20 mb file following way
public boolean decryptfile() { long millis=calendar.getinstance().gettimeinmillis(); try{ string path=environment.getexternalstoragedirectory().getabsolutepath(); inputstream fis = new fileinputstream(path+"/download/circus.pbf"); file outfile = new file(path+"/download/circus.zip"); int read = 0; if (!outfile.exists()) outfile.createnewfile(); fileoutputstream fos = new fileoutputstream(outfile); ivparameterspec ive = new ivparameterspec(key2.getbytes("utf-8")); secretkeyspec skeyspec = new secretkeyspec(key1.getbytes("utf-8"), "aes"); cipher cipher = cipher.getinstance("aes/cbc/pkcs5padding"); cipher.init(cipher.encrypt_mode, skeyspec, ive); 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(); log.e("decryption:", (calendar.getinstance().gettimeinmillis() - millis) / (1000 + 0.0) + " sec"); return true; } catch(ioexception ex){ ex.printstacktrace(); } catch(invalidalgorithmparameterexception ex){ ex.printstacktrace(); } catch(nosuchpaddingexception ex){ ex.printstacktrace(); } catch(invalidkeyexception ex){ ex.printstacktrace(); } catch(nosuchalgorithmexception ex){ ex.printstacktrace(); } return false; } public boolean encryptfile() { long millis= calendar.getinstance().gettimeinmillis(); // here read cleartext. try { string path=environment.getexternalstoragedirectory().getabsolutepath(); inputstream fis = new fileinputstream(path+"/download/circus.zip"); /*file folder=new file(dir); folder.mkdir();*/ file outfile = new file(path+"/download/circus.pbf"); int read = 0; if (!outfile.exists()) outfile.createnewfile(); fileoutputstream encfos = new fileoutputstream(outfile); ivparameterspec ive = new ivparameterspec(key2.getbytes("utf-8")); secretkeyspec skeyspec = new secretkeyspec(key1.getbytes("utf-8"), "aes"); cipher cipher = cipher.getinstance("aes/cbc/pkcs5padding"); cipher.init(cipher.decrypt_mode, skeyspec, ive); // wrap output stream cipheroutputstream cos = new cipheroutputstream(encfos, cipher); // write bytes int b; byte[] d = new byte[8]; while ((b = fis.read(d)) != -1) { cos.write(d, 0, b); } cos.flush(); cos.close(); fis.close(); log.e("encryption:",(calendar.getinstance().gettimeinmillis()-millis)/(1000+0.0)+" sec"); return true; } catch(ioexception ex){ ex.printstacktrace(); } catch(invalidalgorithmparameterexception ex){ ex.printstacktrace(); } catch(nosuchpaddingexception ex){ ex.printstacktrace(); } catch(invalidkeyexception ex){ ex.printstacktrace(); } catch(nosuchalgorithmexception ex){ ex.printstacktrace(); } return false; } and got 325 sec decrypting time. it's long. how can use decrypting not on file partially on selected bytes
e/decryption:﹕ 325.862 sec please recommend me other encryption method or partial encryption
is there reason why using such small byte buffer?
byte[] d = new byte[8];
i suggest play around array size, e.g.
byte[] d = new byte[16 * 1024]; or
byte[] d = new byte[1024 * 1024]; this should enhance performance.
Comments
Post a Comment