fread(&data, 8, 1, input)
tries to read one "item" with 8 bytes into the buffer, and returns the number of items. If less than 8 bytes are left from the current position to EOF, it returns 0.
One possible solution would be to read 8 items à 1 byte instead:
ssize_t amount;
while ((amount = fread(&data, 1, 8, input)) > 0)
{
fwrite(&data, 1, amount, output);
}
Inside the while-block you can then check if amount
is 8 or less, for your
encryption method.