- <#
- .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)
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Friday, 13 August 2010
Get-Sha1Hash.ps1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment