使用OpenSSL进行SHA-256哈希的步骤如下:
打开终端。
使用以下命令进行SHA-256哈希:
openssl dgst -sha256 <文件名>
或者,如果你想对字符串进行哈希,可以使用:
echo -n "你的字符串" | openssl dgst -sha256
注意:-n
参数用于防止在字符串末尾添加换行符。
查看输出。输出将显示文件的SHA-256哈希值。
打开命令提示符。
使用以下命令进行SHA-256哈希:
certutil -hashfile <文件名> SHA256
或者,如果你想对字符串进行哈希,可以使用:
echo 你的字符串 | certutil -hashfile - SHA256
注意:-hashfile -
表示从标准输入读取数据。
查看输出。输出将显示文件的SHA-256哈希值。
Get-FileHash <文件名> -Algorithm SHA256
或者,如果你想对字符串进行哈希,可以使用:$bytes = [System.Text.Encoding]::UTF8.GetBytes("你的字符串")
$hash = [System.Security.Cryptography.HashAlgorithm]::Create("SHA256")
$hash.ComputeHash($bytes)
$hash.ToHex()
注意:第二种方法需要手动处理字节到十六进制的转换。假设你想对文件 example.txt
进行SHA-256哈希:
Linux/macOS:
openssl dgst -sha256 example.txt
Windows命令提示符:
certutil -hashfile example.txt SHA256
Windows PowerShell:
Get-FileHash example.txt -Algorithm SHA256
这些命令将输出文件的SHA-256哈希值。