Don't see why you were ever using a varchar column to store an sha1 hash as: "The hash is a 40-character hexadecimal number." ie fixed size. Now it may be that your characterset changes are messing things up by interpretting the hex as utf8 unicode. "The idea of the UTF8 character set is that various Unicode characters fit into byte sequences of different lengths:
*
Basic Latin letters, digits, and punctuation signs use one byte.
*
Most European and Middle East script letters fit into a two-byte sequence: extended Latin letters (with tilde, macron, acute, grave and other accents), Cyrillic, Greek, Armenian, Hebrew, Arabic, Syriac, and others. "
My fix would be to store the sha1 hash in a binary column of fixed length. I'll bet the problem goes away.