-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifyHash.ps1
More file actions
40 lines (29 loc) · 1.09 KB
/
verifyHash.ps1
File metadata and controls
40 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.SYNOPSIS
An interactive script used to validate the integrity of a file against its published cryptographic hash value.
.DESCRIPTION
The script will prompt for three inputs:
1.) A file must be selected via the file picker.
2.) The known hash value must be provided.
3.) The algorithm used to calculate the hash values must be specified.
Accepted, case-insensitve values are SHA1, SHA256, SHA384, SHA512,
MACTripleDES, MD5, and RIPEMD160.
#>
Add-Type -AssemblyName System.Windows.Forms
"Choose a file..."
$file = New-Object System.Windows.Forms.OpenFileDialog -Property @{
InitialDirectory = [Environment]::GetFolderPath('MyComputer')
Filter = 'All (*.*)|*.*'
}
$null = $file.ShowDialog()
$knownHash = Read-Host "What's the file's known hash?"
$algo = Read-Host "What algorithm was used to calculate this hash?"
$fileHash = Get-FileHash $file.FileName -Algorithm $algo
if ( $fileHash.Hash -eq $knownHash )
{
Write-Output "Hashes match!"
}
else
{
Write-Warning -Message "Hash mismatch! Confirm file integrity and/or known hash.`r`n`r`nExiting..."
}