Search code examples
powershellhashmd5sha1fciv

Why hash code values are different for different tools?


I have created Hash code of an .iso file using fciv.exe. I have used MD5 and SHA1 algorithm. Then I found Get-filehash -Path "c:\MyProject.iso" -Algorithm Sha1 cmdlet in PowerShell, as it is very easy I used that.

But both the tools created different hash code. Hash algorithms should be unique across all the tools. At least that's what my understanding is - am I right? Or it is an expected behavior?

Update: I have taken a sample file and created hash value for that using fciv.exe and also using Powershell.

Fciv.exe created following Sha1

6d9Rar2xh+B5/eEE96pO15EDji0=

Powershell created following Sha1

E9DF516ABDB187E079FDE104F7AA4ED791038E2D

Solution

  • It is the same hash code, but Fciv.exe show it as BASE64 string, while Get-FileHash show it as HEX string:

    $Hash=233,223,81,106,189,177,135,224,121,253,225,4,247,170,78,215,145,3,142,45
    [Convert]::ToBase64String($Hash)
    # 6d9Rar2xh+B5/eEE96pO15EDji0=
    [BitConverter]::ToString($Hash)-replace'-'
    # E9DF516ABDB187E079FDE104F7AA4ED791038E2D
    

    With this piece of code you can add BASE64 representation of hash code to Get-FileHash output:

    Get-FileHash FileName.iso|
    Select-Object Algorithm,
                  @{Name='HashHex';Expression='Hash'},
                  @{Name='HashBase64';Expression={
                      [Convert]::ToBase64String(@(
                          $_.Hash-split'(?<=\G..)(?=.)'|
                          ForEach-Object {[byte]::Parse($_,'HexNumber')}
                      ))
                  }},
                  Path