Correct null byte escaping

The original clean method returned malformed keys. It was casused by null byte handling. This pull request fixes it - both replacement and escape characters are now escaped. The clean method is therefore able to unescape the keys.