我有這個函數加密文件,加密位似乎工作,但我不能讓它覆蓋當前文件。用密文覆蓋明文文件
FileInputStream inputStream = new FileInputStream(input); // Selects file to encrypt
cipher.init(Cipher.ENCRYPT_MODE, secret, ivSpec); // Sets up the encryption
// Creates an the output stream, the encryption is performed here
CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(input + ".secure"), cipher);
byte[] block = new byte[8];
int i;
while ((i = inputStream.read(block)) != -1) // Reads the file
{
cos.write(block, 0, i); // Writes the new file
}
cos.close();
這是工作的罰款,我結束了與original_file_name.txt.secure
一個加密的文件,但我希望它覆蓋原文件。如果我刪除了.secure
位,它不會正確寫入文件。
如何使用加密文本覆蓋文件原始文件?