crypt file in php and download it to the android device, then you need to decrypt it.
a piece on php
$file = fopen('License.pdf', 'rb'); $size = filesize($file); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=License'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); while (!feof($file)) { // print ($data ^ 4); $data = fread($file,4096); if (strlen($data) == 4096) { for ($i = 0; $i < 4096; $i++) { $data[$i] = ($data[$i] ^ $data[0]); } } print $data; }
java piece
BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file)); outFile = new File(filesDir, file.getName()); FileOutputStream out = new FileOutputStream(filePath + "_dec_02"); String base = null; String save = null; byte[] buffer = new byte[4096]; int size; char helpKey = 0; char[] keys = key.toCharArray(); while ((size = reader.read(buffer)) != -1) { if (size == 4096) { // for (int i = 0; i < 4096; i++) { buffer[i] = (byte) (buffer[i] ^ buffer[0]); } } // out.write(buffer); out.flush(); }
what am i doing wrong?