Calculating SHA1 hash algorithm in PowerShell V2.0

a 夏天 提交于 2019-12-01 15:57:32

问题


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.


回答1:


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.




回答2:


Yes, it is possible as it is part of NET 2.0. In fact, the PowerShell Community Extensions use the .NET hash support to implement the Get-Hash command. Version 2.1.1 installs and runs on PowerShell V2.



来源:https://stackoverflow.com/questions/27232146/calculating-sha1-hash-algorithm-in-powershell-v2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!