Я преобразую текстовый файл в файл en c следующим образом:
- Прочитать поток ввода файла.
- Шифрование
- Кодирование с использованием базы 64.
- Используйте поток вывода файла для записи в файл .en c.
- Чтение .en c файла через поток ввода файлов
- Декодирование с использованием базы 64.
- de crypt
- Использование потока вывода файла для записи в текст файл.
Я не могу получить тот же формат вывода, что и входной файл. Вывод такой же.
//Encrypt
inFile = new FileInputStream(path + "/" + fileName);
outFile = new FileOutputStream(encfileName);
byte[] input = new byte[64];
int bytesRead;
while ((bytesRead = inFile.read(input)) != -1) {
byte[] output = cipher.update(input, 0, bytesRead);
if (output != null)
outFile.write(Base64.getEncoder().encode(output));
}
byte[] output = cipher.doFinal();
if (output != null)
outFile.write(Base64.getEncoder().encode(output));
//Decrypt
fis = new FileInputStream(path + "/" + encryptedFile);
fos = new FileOutputStream(decryptedFile);
byte[] in = new byte[64];
int read;
while ((read = decoder.wrap(fis).read(in)) != -1) {
byte[] output = cipher.update(in, 0, read);
if (output != null)
fos.write(output);
}
byte[] output = cipher.doFinal();
if (output != null)
fos.write(output);
Есть предложения?