Source Code and Samples

Friday, 2 February 2007

Compute the SHA1 Hash of a File

Description

This powershell script computes the SHA1 hash of a file and displays it in Base64 format on the screen.

Source Code

$fileName = "File1.txt"
$provider = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$hashBytes = $provider.ComputeHash($fileContentBytes)
$hashBytesEncoded = [System.Convert]::ToBase64String($hashBytes)
write-output $hashBytesEncoded

No comments: