为什么sha256哈希键与命令提示符和Powershell不同?

问题描述 投票:1回答:1

所以我目前正在做一个项目,我遇到了完整性哈希。于是就教我用openssl sha256对一个css文件进行哈希练习。我在Terminal、Command prompt和Powershell中都做过。

终端给出的结果和命令提示符一样,但是powershell给出了一个全新的结果。

命令提示符3BmtwdrKmE6lXPHGqB1Z1jEERC8phQpUwTHMblpJ0Gw=。

Command Prompt

终端3BmtwdrKmE6lXPHGqB1Z1jEERC8phQpUwTHMblpJ0Gw=。

Terminal

PowerShellPxkPz8P04XD8Px1ZPzEERC8pPw0KVD8xP25aST9sDQo=。

PowerShell

tl;dr

基本上我只是想知道终端和命令提示符到powershell之间的不同输出。

号外。

我对网络安全真的很感兴趣,我想多学习,提升技能,做一个独角兽。欢迎给我批评建议<3。

powershell terminal openssl command-prompt sha
1个回答
1
投票

你处理的是Command Prompt、PowerShell和OpenSSL在这些shell中运行时对这种输出编码的差异。

要想从Command Prompt中看到你的活动代码页,请运行以下命令 chcp.com. 要在PowerShell中查看你的活动输出编码,请检查 $OutputEncoding 变量.注意:你会看到代码页面的差异。

您可能会徒劳地尝试将两者设置为相同的输出编码类型,但OpenSSL很可能仍然会报告差异。

作为一个例子,你可以在PowerShell中用审查所有输出编码类型的OpenSSL输出。

[System.Text.Encoding]::GetEncodings() | % { "`n`nCodePage $($_.CodePage):"; $OutputEncoding = [System.Text.Encoding]::GetEncoding($_.CodePage); openssl dgst -sha256 -binary .\index-styles.css | openssl base64 -A }

注意:与OpenSSL的命令提示符输出相比,我怀疑是否有类似的哈希值列出。

无论如何,为了避免这个问题,我建议使用OpenSSL内置的 -out file 参数,然后调用OpenSSL两次,而不是依靠管道(|):

openssl dgst -sha256 -binary -out .\index-styles.out .\index-styles.css
openssl base64 -A -in .\index-styles.out

当你在命令提示符和PowerShell中使用了 -out file 然后 -in file

希望对你有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.