Implementing your own signature code increases the likelihood of subtle (or not so subtle) issues that may occasionally lead to invalid signatures. Using the wrong escaping could be a cause of intermittent issues since it may sometimes work, but other times fail, based on the contents of the strings to be escaped. So, definitely use a tried and tested library wherever possible. Also, make sure your nonce generation is sufficiently random an unlikely to repeat itself. Finally, the system clock needs to be accurate, as a timestamp that is too old will definitely be rejected.