Windows 相当于 linux cksum 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12276426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:15:22  来源:igfitidea点击:

Windows equivalent of linux cksum command

windowslinuxsolarischecksum

提问by AabinGunz

I am looking for a way to compute crc checksum cross platform.

我正在寻找一种计算 crc 校验和跨平台的方法。

cksumworks on Linux, AIX, HP-UX Itanium, Solaris, is there a equivalent command of linux cksumin windows too?

cksum适用于 Linux、AIX、HP-UX Itanium、Solaris,cksum在 Windows 中是否也有等效的 linux 命令?

%cksum run.sh
1491301976 652 run.sh

Note: no third party tool

注意:没有第三方工具

采纳答案by Cassian

In Windows (command prompt) you can use CertUtil, here is the syntax:

在 Windows(命令提示符)中,您可以使用 CertUtil,语法如下:

CertUtil [Options] -hashfile InFile [HashAlgorithm]

for syntax explanation type in cmd:

对于 cmd 中的语法解释类型:

CertUtil -hashfile -?

example:

例子:

CertUtil -hashfile C:\myFile.txt MD5

default is SHA1 it supports: MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512. Unfortunately no CRC32 as Unix shell does.

默认为 SHA1,它支持:MD2、MD4、MD5、SHA1、SHA256、SHA384、SHA512。不幸的是,没有像 Unix shell 那样的 CRC32。

Here is a link if you want to find out more https://technet.microsoft.com/en-us/library/cc732443.aspx#BKMK_menu

如果您想了解更多信息,点击这里的链接https://technet.microsoft.com/en-us/library/cc732443.aspx#BKMK_menu

回答by RyanB

It looks as if there is an unsupported tool for checksums from MS. It's light on features but appears to do what you're asking for. It was published in August of 2012. It's called "Microsoft File Checksum Integrity Verifier".

看起来好像有一个不受支持的工具用于 MS 的校验和。它的功能很简单,但似乎可以满足您的要求。它于 2012 年 8 月发布。它被称为“Microsoft File Checksum Integrity Verifier”。

http://www.microsoft.com/en-us/download/details.aspx?id=11533

http://www.microsoft.com/en-us/download/details.aspx?id=11533

回答by sst

Here is a C# implementation of the *nix cksum command line utility for windows https://cksum.codeplex.com/

这是用于 Windows 的 *nix cksum 命令行实用程序的 C# 实现https://cksum.codeplex.com/

回答by HIlitec

To avoid annoying non-checksum lines : CertUtil -v -hashfile "your_file" SHA1 | FIND /V "CertUtil" This will display only line(s) NOTcontaning CertUtil

为避免烦人的非校验和行: CertUtil -v -hashfile "your_file" SHA1 | FIND /V "CertUtil" 这将只显示不包含CertUtil 的行

回答by Chris

In combination of answers of @Cassian and @Hllitec and from https://stackoverflow.com/a/42706309/1001717here my solution, where I put (only!) the checksum value into a variable for further processing:

结合@Cassian 和@Hllitec 的答案以及来自https://stackoverflow.com/a/42706309/1001717的答案,这里是我的解决方案,我将(仅!)校验和值放入变量中以进行进一步处理:

for /f "delims=" %i in ('certutil -v -hashfile myPackage.nupkg SHA256 ^| find /i /v "sha256" ^| find /i /v "certutil"') do set myVar=%i

To test the output you can add a piped echo command with the var:

要测试输出,您可以使用 var 添加管道回显命令:

for /f "delims=" %i in ('certutil -v -hashfile myPackage.nupkg SHA256 ^| find /i /v "sha256" ^| find /i /v "certutil"') do set myVar=%i | echo %myVar%

A bit off-topic, but FYI: I used this before uploading my NuGet package to Artifactory. BTW. as alternative you can use JFrog CLI, where checksum is calculated automatically.

有点跑题,但仅供参考:我在将 NuGet 包上传到 Artifactory 之前使用了它。顺便提一句。作为替代方案,您可以使用 JFrog CLI,它会自动计算校验和。

回答by stacki

In the year 2019, Microsoft offers the following solution for Windows 10. This solution works for SHA256 checksum.

2019 年,Microsoft 为 Windows 10 提供了以下解决方案。该解决方案适用于 SHA256 校验和。

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-6

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-6

Press the Windows key. Type PowerShell. Select Windows Powershell. Press Enter key. Paste the command

按 Windows 键。键入 PowerShell。选择 Windows Powershell。按回车键。粘贴命令

Get-FileHash C:\Users\Donald\Downloads\File-to-be-checked-by-sha256.exe | Format-List

Get-FileHash C:\Users\Donald\Downloads\File-to-be-checked-by-sha256.exe | 格式列表

Replace File-to-be-checked-by-sha256.exe by the name of your file to be checked.

将 File-to-be-checked-by-sha256.exe 替换为要检查的文件的名称。

Replace the path to your path where the file is. Press Enter key. Powershell shows then the following

将路径替换为文件所在的路径。按回车键。Powershell显示以下内容

Algorithm : SHA256 Hash : 123456789ABCDEFGH1234567890... Path : C:\Users\Donald\Downloads\File-to-be-checked-by-sha256.exe

算法:SHA256 哈希:123456789ABCDEFGH1234567890...路径:C:\Users\Donald\Downloads\File-to-be-checked-by-sha256.exe