files_encryption: bug fixes for reported problems.

This PR should fix bugs reported at #3641 and #3620.

@schiesbn please review.
@karlitschek it will be great if we can get this in the next beta you are planning, so people have a chance to test this patches.