# Calculate hash values including base64 result

**URL:** <https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195>\
**Category:** PowerShell Help\
**Created:** [November 20, 2023, 3:34pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195 "2023-11-20T15:34:03Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 20, 2023, 3:34pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/1 "2023-11-20T15:34:03Z")

</div>

Hi,

I’m using the following REG script to calculate hash values with a right click on the file. How can I mofify this script to calculate the Base64 hashes for SHA1 and SHA256 as well?

```auto
[HKEY_CLASSES_ROOT\*\shell\hash]
"MUIVerb"="Calculate Hash Value"
"SubCommands"=""

[HKEY_CLASSES_ROOT\*\shell\hash\shell\SHA1]
"MUIVerb"="SHA1"

[HKEY_CLASSES_ROOT\*\shell\hash\shell\SHA1\command]
@="powershell -noexit get-filehash -literalpath '%1' -algorithm SHA1 | format-list"

[HKEY_CLASSES_ROOT\*\shell\hash\shell\SHA256]
"MUIVerb"="SHA256"

[HKEY_CLASSES_ROOT\*\shell\hash\shell\SHA256\command]
@="powershell -noexit get-filehash -literalpath '%1' -algorithm SHA256 | format-list"

```

For example:

```auto
Algorithm : SHA256 and Base64
Hash : 6A33947B40670D815B3DC7D1435FB0B432BECA371FD5E05E2E5190AEF337DF9B
Hash b64 : ajOUe0BnDYFbPcfRQ1+wtDK+yjcf1eBeLlGQrvM335s=
Path : C:\Windows\explorer.exe

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 5:19pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/2 "2023-11-20T17:19:46Z")

</div>

Maxstar,  
Welcome to the forum. 👋🏼

What exactly do you mean by …

> [@Maxstar](#):
>
> calculate the Base64 hashes

?

If I got it right the Base64 represantation of the hash string in your example would be

```auto
NgBBADMAMwA5ADQANwBCADQAMAA2ADcAMABEADgAMQA1AEIAMwBEAEMANwBEADEANAAzADUARgBCADAAQgA0ADMAMgBCAEUAQwBBADMANwAxAEYARAA1AEUAMAA1AEUAMgBFADUAMQA5ADAAQQBFAEYAMwAzADcARABGADkAQgA=

```

Does this help:

> **[PowerShell Encoding & Decoding (Base64)](https://adsecurity.org/?p=478)**
>
> PowerShell provides an easy method for Base64 encoding and decoding. Encoding: $Text = 'This is a secret and should be hidden' $Bytes = ::Unicode.GetBytes($Text) $EncodedText =::ToBase64String($Bytes) $EncodedText The result is this base64 encoded...

?

May I ask what’s the purpose of that requirement? Whatfor do you need that?

**EDIT:**  
BTW: If you do it like this you could have both hashes in one call:

```auto
$Path = 'C:\Windows\explorer.exe'
[PSCustomObject]@{
    Path = $Path
    SHA1 = (Get-FileHash -Path $Path -Algorithm SHA1).Hash
    SHA256 = (Get-FileHash -Path $Path).Hash
} |
Format-List

```

The output looks like this:

```auto
Path : C:\Windows\explorer.exe
SHA1 : 38013D682C7F81AB01367298BD27FE14A18B005F
SHA256 : DC66E22C929AA80A3265F19E506885A00DFEC3ADAA9A14CD89C3F4E820E4C6DB

```

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 20, 2023, 5:43pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/3 "2023-11-20T17:43:55Z")

</div>

Hi Olaf,

The purpose of this script is to check hash values of WinSxS payload files to determine the hash value as SHA256 as well as SHA256 Base64 like this example below…

```auto
Algorithm : SHA256 and Base64
Hash : 6A33947B40670D815B3DC7D1435FB0B432BECA371FD5E05E2E5190AEF337DF9B
Hash b64 : ajOUe0BnDYFbPcfRQ1+wtDK+yjcf1eBeLlGQrvM335s=

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 5:49pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/4 "2023-11-20T17:49:56Z")

</div>

> [@Maxstar](#):
>
> SHA256 as well as SHA256 Base64 like this example below…

How did you _calculate_ the Base64 value?

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 20, 2023, 5:57pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/5 "2023-11-20T17:57:41Z")

</div>

To calculate the SHA256 Base64 I use HashTab - [Download HashTab - MajorGeeks](https://www.majorgeeks.com/files/details/hashtab.html)

What I want is to create is an REG which will show both hash values.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 6:10pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/6 "2023-11-20T18:10:36Z")

</div>

> [@Maxstar](#):
>
> To calculate the SHA256 Base64 I use HashTab - [Download HashTab - MajorGeeks](https://www.majorgeeks.com/files/details/hashtab.html)

I just installed HashTab on a test PC but there is no SHA256 Base64 hash!?! 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 6:40pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/7 "2023-11-20T18:40:23Z")

</div>

> [@Maxstar](#):
>
> What I want is to create is an REG which will show both hash values.

OK, if you know how to actually calculate the value you’re after you can use this reg key as a blueprint:

```auto
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\SuperHash]
"MUIVerb"="Super Hash"

[HKEY_CLASSES_ROOT\*\shell\SuperHash\command]
@="powershell -NoLogo -NoProfile -NoExit -Command '%1' | Select-Object -Property @{Name = 'Path'; Expression = {$_}},@{Name = 'SHA1'; Expression = {(Get-FileHash -Path $_ -Algorithm SHA1).Hash}},@{Name = 'SHA256'; Expression = {(Get-FileHash -Path $_).Hash}} | Format-List"

```

The output looks like this:

```auto
Path : C:\Windows\explorer.exe
SHA1 : 38013D682C7F81AB01367298BD27FE14A18B005F
SHA256 : DC66E22C929AA80A3265F19E506885A00DFEC3ADAA9A14CD89C3F4E820E4C6DB

```

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 11:45am UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/8 "2023-11-21T11:45:23Z")

</div>

> [@Olaf](#):
>
> OK, if you know how to actually calculate the value you’re after you can use this reg key as a blueprint:

Thanks…

I found the following at StackOverflow [base64 - How to get sha256 hash output as binary data instead of hex using powershell? - Stack Overflow](https://stackoverflow.com/questions/58815699/how-to-get-sha256-hash-output-as-binary-data-instead-of-hex-using-powershell)

But I don’t know I can use this example in your blueprint.

```auto
$ClearString= "test"
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
$hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ClearString))
# $hash is a Byte[] array

# convert to Base64
[Convert]::ToBase64String($hash)

```

Edit:

I also found this example: [sha1 - Powershell SHA-1 and base64 encode - Stack Overflow](https://stackoverflow.com/questions/66884395/powershell-sha-1-and-base64-encode)

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 21, 2023, 12:30pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/9 "2023-11-21T12:30:22Z")

</div>

> [@Maxstar](#):
>
> I found the following at StackOverflow [base64 - How to get sha256 hash output as binary data instead of hex using powershell? - Stack Overflow](https://stackoverflow.com/questions/58815699/how-to-get-sha256-hash-output-as-binary-data-instead-of-hex-using-powershell)

So you’re hashing the hash. What purpuse does that serve?

> [@Maxstar](#):
>
> The purpose of this script is to check hash values of WinSxS payload files to determine the hash value as SHA256 as well as SHA256 Base64

And what do you do with the hashes and the hash of the hash coded in Base64??? 🤔

And I’d like to ask again:

> [@Olaf](#):
>
> How did you _calculate_ the Base64 value?

> [@Olaf](#):
>
> I just installed HashTab on a test PC but there is no SHA256 Base64 hash!?! 🤷🏼‍♂️

```auto
@="powershell -NoLogo -NoProfile -NoExit -Command '%1' | Select-Object -Property @{Name = 'Path'; Expression = {$_}},@{Name = 'SHA1'; Expression = {(Get-FileHash -Path $_ -Algorithm SHA1).Hash}},@{Name = 'SHA256'; Expression = {(Get-FileHash -Path $_).Hash}},@{Name='Base64';Expression={[Convert]::ToBase64String(([System.Security.Cryptography.HashAlgorithm]::Create('sha256')).ComputeHash([System.Text.Encoding]::UTF8.GetBytes((Get-FileHash -Path $_).Hash)))}}| Format-List"

```

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 12:33pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/10 "2023-11-21T12:33:34Z")

</div>

> [@Olaf](#):
>
> I just installed HashTab on a test PC but there is no SHA256 Base64 hash!?!

You’ll need to activate SHA256 Base64 from the settings option, it is not enabled by default.

 ![hashtab](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/e/e851814c917503bf4f8cfed5ab5b149d69213236.png)

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 12:38pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/11 "2023-11-21T12:38:58Z")

</div>

> [@Olaf](#):
>
> And what do you do with the hashes and the hash of the hash coded in Base64??? 🤔

Sometimes the CBS.log will show the default SHA256 value, and sometimes the Base64 variant. Also for the SHA1 values. So I want to create a script (reg file) to calculate both values to check if a payload file is corrupted or not.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 21, 2023, 1:47pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/12 "2023-11-21T13:47:02Z")

</div>

> [@Maxstar](#):
>
> So I want to create a script (reg file) to calculate both values to check if a payload file is corrupted or not.

> [@Olaf](#):
>
> > [@Olaf](#):
> >
> > I just installed HashTab on a test PC but there is no SHA256 Base64 hash!?! 🤷🏼‍♂️
> 
> ```auto
> @="powershell -NoLogo -NoProfile -NoExit -Command '%1' | Select-Object -Property @{Name = 'Path'; Expression = {$_}},@{Name = 'SHA1'; Expression = {(Get-FileHash -Path $_ -Algorithm SHA1).Hash}},@{Name = 'SHA256'; Expression = {(Get-FileHash -Path $_).Hash}},@{Name='Base64';Expression={[Convert]::ToBase64String(([System.Security.Cryptography.HashAlgorithm]::Create('sha256')).ComputeHash([System.Text.Encoding]::UTF8.GetBytes((Get-FileHash -Path $_).Hash)))}}| Format-List"
> 
> ```

And … does it work?

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 1:57pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/13 "2023-11-21T13:57:20Z")

</div>

It shows a SHA256 value in base64 format, but it is not the same hash value when I use HashTab? So apparently something goes wrong with calculating the Base64 hash file for some reason?

For example: the installer of [Download HashTab 6.0.0.34](https://www.majorgeeks.com/mg/getmirror/hashtab,1.html)

PowerShell result:

```auto
Path : C:\Users\Administrator\Desktop\HashTab_v6.0.0.34_Setup.exe
SHA256 : B8FF1DD80F370B137922A9DD2D8B04E16FD4F8681458F92C566E65E2E80724AD
Base64 : WX6U+TEPyNdf33UKQJocfljFruqqGdzYBUTUSSjfGT0=

```

HashTab result:

```auto
B8FF1DD80F370B137922A9DD2D8B04E16FD4F8681458F92C566E65E2E80724AD
uP8d2A83CxN5IqndLYsE4W/U+GgUWPksVm5l4ugHJK0=

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 21, 2023, 2:17pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/14 "2023-11-21T14:17:31Z")

</div>

> [@Maxstar](#):
>
> It shows a SHA256 value in base64 format, but it is not the same hash value when I use HashTab? So apparently something goes wrong with calculating the Base64 hash file for some reason?

That’s what I meant with …

> [@Olaf](#):
>
> if you know how to actually calculate the value you’re after

and

> [@Olaf](#):
>
> So you’re hashing the hash. What purpuse does that serve?

🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 2:41pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/15 "2023-11-21T14:41:32Z")

</div>

That’s the whole point, I don’t know exactly how HashTab is calculating the Base64 value. I see a lot of different options to covert HEX to Base64. So I don’t know how to get the same Base64 hash as showed by HashTab.

[https://asecuritysite.com/powershell/enc05](https://asecuritysite.com/powershell/enc05)

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 21, 2023, 3:32pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/16 "2023-11-21T15:32:27Z")

</div>

Try this:

```auto
@="powershell -NoLogo -NoProfile -NoExit -Command '%1' | Select-Object -Property @{Name = 'Path'; Expression = {$_}},@{Name = 'SHA1'; Expression = {(Get-FileHash -Path $_ -Algorithm SHA1).Hash}},@{Name = 'SHA256'; Expression = {(Get-FileHash -Path $_).Hash}},@{Name='Base64';Expression={[System.Convert]::ToBase64String(([System.Security.Cryptography.SHA256]::Create()).ComputeHash((Get-Content -Path $_ -Encoding Byte)))}}| Format-List"

```

Attention !! … it is very slow.

**Edit:**

Try this as well … it might be faster:

```auto
@="powershell -NoLogo -NoProfile -NoExit -Command '%1' | Select-Object -Property @{Name = 'Path'; Expression = {$_}},@{Name = 'SHA1'; Expression = {(Get-FileHash -Path $_ -Algorithm SHA1).Hash}},@{Name = 'SHA256'; Expression = {(Get-FileHash -Path $_).Hash}},@{Name='Base64';Expression={[System.Convert]::ToBase64String(([System.Security.Cryptography.SHA256]::Create()).ComputeHash((Get-Content -Path $_ -Encoding Byte -ReadCount 0)))}}| Format-List"

```

---

<div class="post-metadata">

**Author:** ![Maxstar](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Maxstar](https://forums.powershell.org/u/Maxstar)\
**Post date:** [November 21, 2023, 4:01pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/17 "2023-11-21T16:01:13Z")

</div>

Amazing!!! Thank you very much, this works absolutely great… 👍 👍 👍

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 21, 2023, 4:05pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/18 "2023-11-21T16:05:39Z")

</div>

For the record - it is the Base64 encoded SHA256 hash of the byte stream of the file content. ☝🏼

Yet another piece of for me useless information in my brain. 😏 🤟🏼

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:13pm UTC](https://forums.powershell.org/t/calculate-hash-values-including-base64-result/23195/19 "2024-05-16T20:13:40Z")

</div>


