Rewrite of encrypt hook for ArchLinux. Flow control and support for detached header