title: How to encrypt & encode a password with PowerShell v2?
body: <p>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.</p>
  
  <p>I tried using:
      PS C:\Program Files (x86)\PowerGUI> $password = "password not shown here"</p>
  
  <pre><code>PS C:\Program Files (x86)\PowerGUI&gt; $bytes =  System.Text.Encoding]::Unicode.GetBytes($password)
  
  PS C:\Program Files (x86)\PowerGUI&gt; $encodedString = [Convert]::ToBase64CharArray($bytes)
  </code></pre>
  
  <p>But I got this back:</p>
  
  <p>Cannot find an overload for "ToBase64CharArray" and the argument count: "1".
  At line:1 char:46
  + $encodedString = [Convert]::ToBase64CharArray &lt;&lt;&lt;&lt; ($bytes)
      + CategoryInfo          : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest</p>
  
  <p>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.</p>
  
  <p><strong>Any ideas how to do this only in powershell using SHA1 encryption and base64 encoding?</strong></p>
  
  <hr>
  
  <p>Okay, this works for the encoding, thanks to Jonathan for this part:</p>
  
  <pre><code>$str = "pwd"
  $bytes = [System.Text.Encoding]::Unicode.GetBytes($str)
  $encodedStr = [Convert]::ToBase64String($bytes)
  
  # and the result:
  Write-Host $encodedStr
  cAB3AGQA
  </code></pre>
  
  <p>I noticed the function call :: is sensitive to whitespace.  This works for the encryption piece.</p>
  
  <pre><code>$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
  </code></pre>