-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include modules hash in golden hash, windows
- Loading branch information
Showing
2 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Creates a SHA of all files in the directory but ignores their metadata | ||
## This is useful when you want to ignore all timestamps of a zip, for example: | ||
## You can extract the contents to a directory, then run this. | ||
## Usage: powershell Sha-Of-Directory.ps1 <DIRECTORY> <sha version: 1, 256, or 512> | ||
|
||
$Directory=$args[0] | ||
$ShaA=$args[1] | ||
|
||
# First, create a hash algorithm object using SHA256. | ||
$Algorithm = [System.Security.Cryptography.HashAlgorithm]::Create("SHA" + $ShaA) | ||
|
||
# Next, create a cryptographic stream of data using the SHA256 hash algorithm. | ||
$CryptoStream = [System.Security.Cryptography.CryptoStream]::new( | ||
([System.IO.Stream]::Null), | ||
$Algorithm, | ||
"Write" | ||
) | ||
|
||
# Retrieve each file and copy the data into the cryptographic stream. | ||
echo $Directory | ||
foreach ($File in Get-ChildItem -Recurse -Path $Directory -File) { | ||
# Write-Host $File | ||
$FileStream = [io.file]::OpenRead($File.FullName) | ||
$FileStream.CopyTo($CryptoStream) | ||
} | ||
|
||
# Close all files and close out the cryptographic stream. | ||
$CryptoStream.FlushFinalBlock() | ||
|
||
# Combine all of the hashes as hexadecimal formats "X2" and join the values. | ||
($Algorithm.Hash | ForEach-Object {$_.ToString("X2")}) -join '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters