我有这个函数加密文件,加密位似乎工作,但我不能让它覆盖当前文件。用密文覆盖明文文件
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
位,它不会正确写入文件。
如何使用加密文本覆盖文件原始文件?