Last active
          June 22, 2017 19:11 
        
      - 
      
 - 
        
Save marcgeld/bf690d174d0fe9e2cfca4d6a64b12a2b to your computer and use it in GitHub Desktop.  
    Powershell: Calculate Hashcode from byteArray
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Calculate Hashcode from byteArray | |
| function Get-HashcodeFromByteArray { | |
| [CmdletBinding()] | |
| Param ( | |
| [Parameter(Mandatory=$true)] | |
| [byte[]] $byteArray = $(Throw("-byteArray is required")), | |
| [ValidateSet("sha256","md5")] | |
| [string]$algorithm=("sha256") | |
| ) | |
| Process{ | |
| Write-Verbose "Get-HashcodeFromByteArray" | |
| $crypto = [System.Security.Cryptography.HashAlgorithm]::Create($algorithm) | |
| $hashcode = [BitConverter]::ToString( $crypto.ComputeHash( $bytearray ) ) | |
| Write-Verbose "Hashcode $hashcode" | |
| Write-Output $hashcode | |
| } | |
| } | |
| [System.Text.Encoding] $enc = [System.Text.Encoding]::UTF8 | |
| Write-Output ( Get-HashcodeFromByteArray $enc.GetBytes( "some text to encode" ) | Out-String ) | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment