D
D
Dmitry2016-08-12 11:11:58
PHP
Dmitry, 2016-08-12 11:11:58

PHP encryption and decryption - android. What's wrong?

I encrypt the file and download it, then I decrypt it on the Android device, what could be the problem?

$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;
}

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-08-12
@Scotik

What did you want to achieve with this "algorithm"?

for ($i = 0; $i < 4096; $i++) {
      $data[$i] = ($data[$i] ^ $data[0]);
    }

At the zero step $data[0] = $data[0] ^ $data[0] = 0;
Then you xorize all other elements of the array with zero. And they don't change.
In decryption, the opposite is true - the zero element cannot be restored in any way.
Plus, I don't know how you iterate in PHP. Java has two bytes.
Well, canonical: security throught obscurity is bad.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question