Clearly, you can't use any trim functions, because the last byte can
be indistinguishable from a space, as you've found.
I believe the hash function you're using always results in a 256-bit
result (so 32 bytes, or 64 hex digits). So simply always grab that