Fixed the file encryption and decryption bug

Seems you need to do a output.flush() so that last part of the file
will be written to the encrypted file