3

My question is only about file hashing rather than hashing function in general. My assumption is that the value of a file checksum/hashing is case insensitive. My concern is that I cannot find any online documentation to confirm that. I only got the following two points to support my claim.

  1. This link contains some file hash values. None of them contains any capital letter. https://www.virtualbox.org/download/hashes/6.1.2/SHA256SUMS

  2. When I use Powershell Get-FileHash cmdlet, all returns are capitals. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7

Can anyone help me confirm my assumption, and provide some documentation on files in Windows as well as in Linux OS?

Seaport
  • 153
  • 2
  • 14
  • 1
    You are looking to a hexadecimal representation of a binary value. Hexadecimal values can be written in both lowercase and uppercase. Quote from https://en.wikipedia.org/wiki/Hexadecimal: "*most often the symbols "0"–"9" to represent values zero to nine, and "A"–"F" (or alternatively "a"–"f") to represent values ten to fifteen*". Meaning, if it concerns the same file contents `$Value.ToUpper()` should return a case sensitive comparable value. Note that string compares in PowerShell are insensitive by default, this means that `$Value1 -eq $Value2` returns true if the files are equal – iRon Jan 23 '20 at 07:05

2 Answers2

3

Hashes and checksums are often presented in hexadecimal notation. Although it is common to use upper case A-F instead of lower case a-f, it does not make any difference.

As for a reference, the question is so basic that it's hard to find a solid reference. One is ISO/IEC 9899 standard for the C programming language:

A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and the letters a (or A) through f (or F) with values 10 through 15 respectively.

In some use cases, such as CSS lower case might be preferred, as it is more pleasant to read among other lower case characters. .Net's Int32.ToString supports standard numeric formaters. x for lower case, X for upper case.

In System.Convert, there's ToInt32 that will convert values from one base into 32 bit integers. Let's see how hex digit AA is converted to decimal in different cases. Like so,

[convert]::toint32("aa", 16)
170
[convert]::toint32("AA", 16)
170
[convert]::toint32("aA", 16)
170
[convert]::toint32("Aa", 16)
170

Every letter case combination represents the same decimal value, 170. Don't try this on hashes though, as those are usually larger than 32 bit integers.

vonPryz
  • 22,996
  • 7
  • 54
  • 65
  • Thanks for pointing me in the right direction. So what is really matters is how the hushing result (bits) are [encoded](https://en.wikipedia.org/wiki/Binary-to-text_encoding). Now it is safe to say that Windows/Linux file checksum is encoded in hexadecimal (Base16) and this is why it is case-insensitive. – Seaport Jan 23 '20 at 16:27
3

My question is only about file hashing rather than hashing function in general. My assumption is that the value of a file checksum/hashing is case insensitive.

Hashes are byte sequences, they don't have case at all.

Hashes are generally encoded as hexadecimal for display, for which the 6 "letters" (a to f) can be either case. That's mostly a style issue though I've known system which did object when getting the "wrong" case (some would only accept lowercase, others only uppercase).

Also beware that e.g. it's not unheard of to store or show hashes as base64 where case is relevant. Without knowing why you're asking (e.g. is it idle musing, or do you have an actual use case) it's hard to answer completely categorically.

Masklinn
  • 34,759
  • 3
  • 38
  • 57