I'm trying to hit a web service using an SHA1 64 bit encoded password, but I'm not sure how to code this in powershell.
I tried using: PS C:\Program Files (x86)\PowerGUI> $password = "password not shown here"
PS C:\Program Files (x86)\PowerGUI> $bytes = System.Text.Encoding]::Unicode.GetBytes($password)
PS C:\Program Files (x86)\PowerGUI> $encodedString = [Convert]::ToBase64CharArray($bytes)
But I got this back:
Cannot find an overload for "ToBase64CharArray" and the argument count: "1". At line:1 char:46 + $encodedString = [Convert]::ToBase64CharArray <<<< ($bytes) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
I'm new with powershell, so this may not even be the right code to use. I tried to modify an example I found online.
Any ideas how to do this only in powershell using SHA1 encryption and base64 encoding?
Okay, this works for the encoding, thanks to Jonathan for this part:
$str = "pwd"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($str)
$encodedStr = [Convert]::ToBase64String($bytes)
# and the result:
Write-Host $encodedStr
cAB3AGQA
I noticed the function call :: is sensitive to whitespace. This works for the encryption piece.
$Sha1provider = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$hashBytes = $Sha1provider.ComputeHash($bytes)
Write-Host $hashBytes
114 168 243 129 97 21 246 249 22 4 38 215 241 185 174 86 116 201 7 7