From 6e6974ec0897474bffe5460c7605ac7c0562f581 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 26 Nov 2024 07:58:23 +0100 Subject: [PATCH] Added get-sha512.ps1 --- scripts/get-md5.ps1 | 18 ++++++++++-------- scripts/get-sha1.ps1 | 20 +++++++++++--------- scripts/get-sha256.ps1 | 21 +++++++++++---------- scripts/get-sha512.ps1 | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 scripts/get-sha512.ps1 diff --git a/scripts/get-md5.ps1 b/scripts/get-md5.ps1 index b57f7f91..99176e66 100755 --- a/scripts/get-md5.ps1 +++ b/scripts/get-md5.ps1 @@ -3,10 +3,11 @@ Prints the MD5 checksum of a file .DESCRIPTION This PowerShell script calculates and prints the MD5 checksum of the given file. -.PARAMETER file - Specifies the path to the file + NOTE: MD5 is no longer considered secure, use it for simple change validation only! +.PARAMETER path + Specifies the file path to the file .EXAMPLE - PS> ./get-md5 C:\MyFile.txt + PS> ./get-md5.ps1 C:\MyFile.txt ✅ MD5 hash is 041E16F16E60AD250EB794AF0681BD4A .LINK https://github.com/fleschutz/PowerShell @@ -14,16 +15,17 @@ Author: Markus Fleschutz | License: CC0 #> -param([string]$file = "") +param([string]$path = "") try { - if ($file -eq "" ) { $file = Read-Host "Enter path to file" } + if ($path -eq "" ) { $path = Read-Host "Enter the file path" } + if (-not(Test-Path $path -pathType leaf)) { throw "Invalid file path given: $path" } - $Result = Get-Filehash $file -algorithm MD5 + $result = Get-FileHash -path $path -algorithm MD5 - "✅ MD5 hash is $($Result.Hash)" + "✅ MD5 hash is $($result.Hash)" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } diff --git a/scripts/get-sha1.ps1 b/scripts/get-sha1.ps1 index 9906b73c..46b62e6d 100755 --- a/scripts/get-sha1.ps1 +++ b/scripts/get-sha1.ps1 @@ -1,12 +1,13 @@ <# .SYNOPSIS - Prints the SHA1 checksum of a file + Prints the SHA1 hash of a file .DESCRIPTION This PowerShell script calculates and prints the SHA1 checksum of the given file. -.PARAMETER file - Specifies the path to the file + NOTE: SHA1 is no longer considered secure, use it for simple change validation only! +.PARAMETER path + Specifies the local file path to the file .EXAMPLE - PS> ./get-sha1 C:\MyFile.txt + PS> ./get-sha1.ps1 C:\MyFile.txt ✅ SHA1 hash is 8105D424D350E308AED92BD9DDEB74A1B53C5D7C .LINK https://github.com/fleschutz/PowerShell @@ -14,16 +15,17 @@ Author: Markus Fleschutz | License: CC0 #> -param([string]$file = "") +param([string]$path = "") try { - if ($file -eq "" ) { $file = Read-Host "Enter the filename" } + if ($path -eq "" ) { $path = Read-Host "Enter the file path" } + if (-not(Test-Path $path -pathType leaf)) { throw "Invalid file path given: $path" } - $Result = get-filehash $file -algorithm SHA1 + $result = Get-FileHash -path $path -algorithm SHA1 - "✅ SHA1 hash is $($Result.Hash)" + "✅ SHA1 hash is $($result.Hash)" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } diff --git a/scripts/get-sha256.ps1 b/scripts/get-sha256.ps1 index 7c33a669..458f6ff4 100755 --- a/scripts/get-sha256.ps1 +++ b/scripts/get-sha256.ps1 @@ -1,29 +1,30 @@ <# .SYNOPSIS - Prints the SHA256 checksum of a file + Prints the SHA256 hash of a file .DESCRIPTION This PowerShell script calculates and prints the SHA256 checksum of the given file. -.PARAMETER file - Specifies the path to the file +.PARAMETER path + Specifies the local file path to the file .EXAMPLE - PS> ./get-sha256 C:\MyFile.txt - ✅ SHA256 hash is: CEB4AD71524996EB8AA3ADCE04F1E45636A4B58B8BF4462E6971CF2E56B4293E + PS> ./get-sha256.ps1 C:\MyFile.txt + ✅ SHA256 hash is CEB4AD71524996EB8AA3ADCE04F1E45636A4B58B8BF4462E6971CF2E56B4293E .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> -param([string]$file = "") +param([string]$path = "") try { - if ($file -eq "" ) { $file = Read-Host "Enter the filename" } + if ($path -eq "" ) { $path = Read-Host "Enter the file path" } + if (-not(Test-Path $path -pathType leaf)) { throw "Invalid file path given: $path" } - $Result = get-filehash $file -algorithm SHA256 + $result = Get-FileHash -path $path -algorithm SHA256 - "✅ SHA256 hash is: $($Result.Hash)" + "✅ SHA256 hash is $($result.Hash)" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } diff --git a/scripts/get-sha512.ps1 b/scripts/get-sha512.ps1 new file mode 100644 index 00000000..a11e83e6 --- /dev/null +++ b/scripts/get-sha512.ps1 @@ -0,0 +1,30 @@ +<# +.SYNOPSIS + Prints the SHA512 hash of a file +.DESCRIPTION + This PowerShell script calculates and prints the SHA512 checksum of the given file. +.PARAMETER path + Specifies the local file path to the file +.EXAMPLE + PS> ./get-sha512.ps1 C:\MyFile.txt + ✅ SHA512 hash is CEB4AD71524996EB8AA3ADCE04F1E45636A4B58B8BF4462E6971CF2E56B4293E +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +param([string]$path = "") + +try { + if ($path -eq "" ) { $path = Read-Host "Enter the file path" } + if (-not(Test-Path $path -pathType leaf)) { throw "Invalid file path given: $path" } + + $result = Get-FileHash -path $path -algorithm SHA512 + + "✅ SHA512 hash is $($result.Hash)" + exit 0 # success +} catch { + "⚠️ Error: $($Error[0])" + exit 1 +}