Fix a bug when writing public key