detect null-byte problem, try import hashlib from c_sha256 import sha256 as c_sha256 str_bytes=b'123' + b'\x00' + b'456' print('[hashlib] {}'.format(hashlib.sha256(str_bytes).digest().hex())) print('[c_sha256] {}'.format(c_sha256.sha256(str_bytes).hex()))