How to get a Hash[] of a specific octet sequence

E.g., Hash[“x”,“SHA256”] and Hash[ByteArray[{120}], “SHA256”] give different hashes, and neither agrees with the SHA256 hash of the single octet 78 (hex). Is there a way to get the hash of a specific octet sequence?

In[1]:= IntegerString[Hash[“x”, “SHA256”], 16, 64]

Out[1]= "2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881"

Assuming your byte sequence is specified as a list of hexadecimal strings, you can do this:

In[70]:= IntegerString[Hash[ExportString[FromDigits[#, 16] & /@ {"78"}, "Byte"], "SHA256"], 16, 64]

Out[70]= "2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881"

Hash[ByteArray[{120}], "SHA256"] doesn’t match Hash["x", "SHA256"] because the former hashes the Wolfram Language expression ByteArray[{120}], not the sequence of bytes itself. To use a sequence of decimal bytes, do this:

IntegerString[
 Hash[ExportString[{120}, "Byte"], 
  "SHA256"], 16, 64]

Both of the above match IntegerString[Hash["x", "SHA256"], 16, 64].