java - Decrypt AES256 encrypted file and save it in the phone -


i'm downloading file stored on remote server, try decrypt using jncryptor, , goes except file have downloaded , store in phone external storage corrupted , cannot open it. can tell me im going wrong?

im trying inputstream file, decrypt it, , save file on external storage.

thanks

here code:

private void downloadfile() {         final string file_url = "https://www.google.com";         final string pass = "password";           new asynctask<void, void, void>() {             @override             protected void doinbackground(void... voids) {                 log.d(tag, "starting");                   jncryptor cryptor = new aes256jncryptor();                  int count;                 try {                     url url = new url(file_url);                     urlconnection conection = url.openconnection();                     conection.connect();                      // useful can show tipical 0-100%                     // progress bar                     int lenghtoffile = conection.getcontentlength();                     // download file                     inputstream input = new bufferedinputstream(url.openstream(),                             8192);                      //decrypt istream                     byte[] b = null;                     byte[] data = null;                     try {                         b = new byte[input.available()];                         input.read(b);                     } catch (ioexception e) {                         log.i("decrypt error", e.tostring());                     }                      aes256jncryptoroutputstream cryptorstream = null;                      bytearrayoutputstream bytestream = new bytearrayoutputstream();                      try {                         cryptorstream = new aes256jncryptoroutputstream(bytestream,                                 pass.tochararray());                      } catch (cryptorexception e) {                         e.printstacktrace();                     }                      try {                         cryptorstream.write(b);                         cryptorstream.flush();                         cryptorstream.close();                     } catch (ioexception e1) {                         e1.printstacktrace();                     }                      byte[] encrypted = bytestream.tobytearray();                      try {                         data = cryptor.decryptdata(encrypted, pass.tochararray());                         log.d(tag, "decrypted");                     } catch (invalidhmacexception e) {                         e.printstacktrace();                     } catch (cryptorexception e) {                         e.printstacktrace();                     }                      if (data != null) {                         log.d(tag, "data ok");                     }                      //end decryption                      // output stream                     //test                     fileoutputstream fos = new fileoutputstream(environment                             .getexternalstoragedirectory().tostring()                             + "/temp.zip");                     fos.write(data);                     fos.close();                     log.d(tag, "file saved ");                      input.close();                     log.d(tag, "done");                 } catch (exception e) {                     log.d(tag, "error: " + e.getmessage());                 }                 return null;             }           }.execute();      } 

p.s. im not getting error or warning in logcat.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -