Are you sure your sha256 function behaves ok? Because it gives me very different values from sha256sum (a Linux command)

For the string "123"

Your function: a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3

echo 123 | sha256sum: 181210f8f9c779c26da1d9b2075bde0127302ee0e3fca38c9a83f5b1dd8e5d3b

Regards.