Fix bug in writing certificate hex strings