Crypto: close file descriptors, fix for utf8 (unit-tested)