Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating SHA1 hash algorithm in PowerShell V2.0

Is it possible to calculate a SHA-1 hash in PowerShell V2.0?

The only information I can find online is with PowerShell V4.0.

like image 232
user3586898 Avatar asked Dec 01 '14 15:12

user3586898


People also ask

How does PowerShell calculate hash?

PowerShell does not provide a cmdlet to compute the hash of a string. However, you can write a string to a stream and use the InputStream parameter of Get-FileHash to get the hash value.

How do I get SHA1 PowerShell?

In modern PowerShell, you can use Get-FileHash -a SHA1 /file/path/file.exe - see also: Get-Help Get-FileHash for help and a list of algorithms supported. It seems that the current default is SHA256 , which is the most common used for website download checksums.

What PowerShell script is used to get the SHA1 hash of a file?

The PowerShell cmdlet Get-FileHash generates hash values both for files or streams of data. A hash is simply a function that converts one value into another. Sometimes the hash value may be smaller to save on space, or the hash value may be a checksum used to validate a file.

What is SHA1 hash generator?

What is a SHA-1 Hash? SHA-1 (Secure Hash Algorithm) is a 160 bit cryptographic hash function created by the NSA in 1995. It creates a 40 byte hash value for the input of the algorithm. SHA-1 is one-way, meaning that the original input cannot be be determined simply by knowing the hash value.


1 Answers

I can't remember back in PowerShell V2 days if .NET 3.5 was typically installed too. I think it's the case.

You can always try the following and see if it works:

$file = 'd:\scripts\sha1.ps1'

$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
[System.BitConverter]::ToString( $sha1.ComputeHash([System.IO.File]::ReadAllBytes($file)))

Replace the value of $file with the name of a file you have.

like image 164
Micky Balladelli Avatar answered Oct 19 '22 15:10

Micky Balladelli