Get-Hash from string

Topics: Developer Forum
Developer
Sep 13, 2007 at 5:24 PM
Can we add a -InputString option for Get-Hash so that when I need a hash of a string I don't have to do:

System.Text.Encoding::UTF8.GetBytes("cow") | Get-Hash -Algorithm "SHA1"

And speaking of that ... can we make a variable in $PSCX to set the default hash algorithm?
Coordinator
Sep 15, 2007 at 7:27 PM
This is an issue with not only Get-Hash but also Format-Hex, Format-Xml, Select-Xml, etc. We need to modify these cmdlets so that rather than binding input by value to the Path parameter, they need to bind by value to the InputObject parameter. Then we can inspect the type of the object and do the right thing.
Coordinator
Sep 15, 2007 at 7:28 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 18, 2008 at 8:49 PM

Jaykul wrote:
Can we add a -InputString option for Get-Hash so that when I need a hash of a string I don't have to do:

System.Text.Encoding::UTF8.GetBytes("cow") | Get-Hash -Algorithm "SHA1"

And speaking of that ... can we make a variable in $PSCX to set the default hash algorithm?



Input strings work now as a result of Oisin's PscxPathInfo refactoring (awesome!). I also added a StringEncoding parameter to Get-Hash so your example above simplifies to:

"cow" | Get-Hash -Alg SHA1 -StringEncoding utf8

I thought about the preference variable but I don't think it is a good idea. The algorithm that is used is fundamental to this cmdlet. Having that change based on a preference variables means that if you ever use this cmdlet in a script you really have to always specifiy the Algorithm. You can't count on the default anymore.
Developer
Feb 19, 2008 at 5:44 PM
lol! programmatic darwinism at work... I never planned that. Sweet!