- <#
- .SYNOPSIS
- This script uses the SHA1 Crypto Provider to hash a file
- .DESCRIPTION
- This script uses SHA1 Cryptoprovider to hash a file and print the hash. A second
- hash is created of the same file, but with a space added. The file I picked is a
- large text file I keep in c:\foo for uses like this!
- .NOTES
- File Name : Get-Sha1HashFile.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- Posted to TechEd Sample Gallery at:
- .EXAMPLE
- PSH [C:\foo]: .\Get-Sha1HashFile.ps1
- Hashing : C:\foo\gd.txt
- Results in : 760bb67356560232
- Hashing : C:\foo\gd.txt + space
- Results in : 4f7b4902168bba7d
- #>
- # Create Input Data
- $file = (ls c:\foo\*.txt | sort -descending length)[0] # get largest file
- $filestr = Get-Content $file
- $filebytes1 = [System.Text.UnicodeEncoding]::Unicode.getbytes($files)
- $filebytes2 = [System.Text.UnicodeEncoding]::Unicode.getbytes($files+" ")
- # Create a New SHA1 Crypto Provider
- $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
- # Now hash that
- $result1 = $sha.ComputeHash($filebytes1)
- "Hashing : {0}" -f $file.FullName
- "Results in : {0}" -f [system.BitConverter]::ToUint64($result1,0).tostring("x")
- $result2 = $sha.ComputeHash($filebytes2)
- "Hashing : {0}" -f " $($file.FullName) + space"
- "Results in : {0}" -f [system.BitConverter]::ToUint64($result2,0).tostring("x")
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label System.Security.Cryptography.Sha1CryptoServiceProvider. Show all posts
Showing posts with label System.Security.Cryptography.Sha1CryptoServiceProvider. Show all posts
Monday, 16 August 2010
Get-Sha1HashFile.ps1
Friday, 13 August 2010
Get-Sha1Hash.ps1
- <#
- .SYNOPSIS
- This script uses the SHA1 Crypto Provider to hash a string
- .DESCRIPTION
- This script creates 2 strings, and a SHA1 Crypto Provider.
- The script then hashes the strings and displays the results.
- .NOTES
- File Name : Get-Sha1Hash.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1cryptoserviceprovider.aspx
- Posted to TechEd Sample Gallery at:
- .EXAMPLE
- PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.Security.Crpytography\Get-Sha1Hash.ps1'
- Hashing : This is a string to hash
- Results in : z→???_r♠W??o???]rv??
- Hashing : this is a string to hash
- Results in : ???☺$?Z??♀???????U?'
- #>
- # Create Input Data
- $enc = [system.Text.Encoding]::ASCII
- $string1 = "This is a string to hash"
- $string2 = "this is a string to hash"
- $data1 = $enc.GetBytes($string1)
- $data2 = $enc.GetBytes($string2)
- # Create a New SHA1 Crypto Provider
- $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
- # Now hash and display results
- $result1 = $sha.ComputeHash($data1)
- "Hashing : {0}" -f $string1
- "Results in : {0}" -f $enc.Getstring($result1)
- ""
- $result2 = $sha.ComputeHash($data2)
- "Hashing : {0}" -f $string2
- "Results in : {0}" -f $enc.Getstring($result2)
Subscribe to:
Posts (Atom)