0

In my batch file I run the below command:

CertUtil -hashfile SomeFile.txt sha256 | findstr /v "hash"

When I run this on my local environment it produces an output such as "8bf5d1b671bf44ebf72e7fc3dcc40d2190543b3bae2a653e1e64d2755dac12cc".

However when I run this on one of my servers using the same command, I get a segmented output instead such as "8b f5 d1 b6 71 bf 44 eb f7 2e 7f c3 dc c4 0d 21 90 54 3b 3b ae 2a 65 3e 1e 64 d2 75 5d ac 12 cc".

The commands I am using are the same and I'm unaware of any elements that are causing the output to look as such. Is there something I'm missing that's causing windows to produce the string above?

  • just use powershell `Get-FileHash -Algorithm SHA256 SomeFile.txt` for consistent output – phuclv Jan 04 '23 at 15:04
  • 1
    The versions of certutil.exe are not the same, and not all versions output the result in hex pairs. – Compo Jan 04 '23 at 15:33
  • I understand now that this is a product of differences in version for certutil. Would there be a sed like operator I could pipe my output to to remove the spaces and get away from the hex pairs? @Compo – SomekindaRazzmatazz Jan 04 '23 at 17:45
  • 1
    You could do it with a `For` loop. Example: ```@For /F "Delims=" %%G In ('%SystemRoot%\System32\certutil.exe -HashFfle "SomeFile.txt" SHA256 2^>NUL ^| %SystemRoot%\System32\find.exe /V ":"') Do @Set "hash=%%G" & SetLocal EnableDelayedExpansion & For %%H In ("!hash: =!") Do @EndLocal & Echo(%%~H```. – Compo Jan 04 '23 at 18:37

1 Answers1

0

Version differences, as explained in comments by Compo above here, attribute to the differences in output between CertUtil in my local and remote servers. @Compo has provided a script to produce the format that coverts between the versions and has solved the issue.