Reputation: 4035
I want to maintain state in a returned closure:
function HashMaker {
$enc = [System.Text.Encoding]::UTF8
$hasher = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
return {
param($value)
[System.BitConverter].ToString($hasher.ComputeHash($enc.GetBytes($value)))
}.GetNewClosure()
}
There's obviously something wrong with this approach
Upvotes: 0
Views: 55
Reputation: 174690
Don't call ToString()
on the [BitConverter]
type itself, call its static ToString()
method:
return {
param($value)
[System.BitConverter]::ToString($hasher.ComputeHash($enc.GetBytes($value)))
}.GetNewClosure()
Notice the ::
instead of .
Upvotes: 3