是否可以在 PowerShell V2.0 中计算 SHA-1 哈希值?
我在网上能找到的唯一信息是PowerShell V4.0。
我不记得在 PowerShell V2 时代是否通常也安装了 .NET 3.5。我想是这样的。
您可以随时尝试以下方法,看看是否有效:
$file = 'd:\scripts\sha1.ps1'
$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
[System.BitConverter]::ToString( $sha1.ComputeHash([System.IO.File]::ReadAllBytes($file)))
将
$file
的值替换为您拥有的文件名。
是的,这是可能的,因为它是 NET 2.0 的一部分。 事实上,PowerShell 社区扩展 使用 .NET 哈希支持来实现
Get-Hash
命令。 版本 2.1.1 在 PowerShell V2 上安装并运行。
计算字符串(不是文件)的 SHA1 哈希值:
$mystring = "Some string and text content here"
$mystream = [IO.MemoryStream]::new([byte[]][char[]]$mystring)
Get-FileHash -InputStream $mystream -Algorithm SHA1
来自 Reddit 帖子