Use StringIO to feed md5 calculation to prevent unicode issues

Fixes #4014