How to get the same hash in Python3 and Mac / Linux terminal? How to get the same hash in Python3 and Mac / Linux terminal? python-3.x python-3.x

How to get the same hash in Python3 and Mac / Linux terminal?


The echo built-in will add a trailing newline yielding a different string, and thus a different hash. Do it like so

echo -n 'test text' | shasum -a 256

If you indeed intended to also hash the newline (I advice against this as it violates POLA), it needs to be fixed up in python like so

hashlib.sha256("{}\n".format("test text").encode('utf-8')).hexdigest()