Question

I'm writing a function to produce a SHA256 hash on a file. Here is the code I use

public string ComputeHash(Byte[] inputBytes)
    {
        Byte[] hashedBytes = new SHA256Managed().ComputeHash(inputBytes);
        return BitConverter.ToString(hashedBytes);
    }

Very simple. The fact is that the hashing produced seems not to be valid, according on a couple of tool I tried and, in effect, is different from any other sha256 string I ever seen (and is not even 256 byte). One result, for example is

12-10-B2-60-24-75-11-95-B5-F7-F6-64-39-C3-22-9F-E7-E7-D4-13-69-18-99-C5-A7-C5-EC-2F-E2-D6-09-19

Even if I trim out every - char, everything is uppercase, while I always saw lowercase rappresentation. (Is that a problem too) I'm wondering if I'm using the library in a correct way. please help

Was it helpful?

Solution

SHA-256 means 256 bits, aka 32 bytes which is what you're seeing.

Lower-case and upper-case are irrelevant here - that's just the representation of the bytes as a string. Ditto whether or not there are hyphens between the bytes. Different tools produce different hex string representations, that's all... so I'd expect "1210B2" to be equivalent to "12-10-b2" etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top