如何在Windows上执行校验和?
有没有一种方法可以在windows机器(如unix/linux机器)上执行校验和如何在Windows上执行校验和?,windows,Windows,有没有一种方法可以在windows机器(如unix/linux机器)上执行校验和 我无法下载任何第三方工具,不知道本机是否有类似的工具?您可以获取该文件的MD5哈希。您将解析文件并将其作为字符串传递到此函数中。e、 g public string GetMD5Hash(string input) { System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptogr
我无法下载任何第三方工具,不知道本机是否有类似的工具?您可以获取该文件的MD5哈希。您将解析文件并将其作为字符串传递到此函数中。e、 g
public string GetMD5Hash(string input)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
string password = s.ToString();
return password;
}
(摘自)
…或作为文件:
protected string GetMD5HashFromFile(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
受保护的字符串GetMD5HashFromFile(字符串文件名)
{
FileStream file=newfilestream(文件名,FileMode.Open);
MD5 MD5=新的MD5CryptoServiceProvider();
字节[]retVal=md5.ComputeHash(文件);
file.Close();
StringBuilder sb=新的StringBuilder();
for(int i=0;i
从Calculate MD5 Checksum for File中获取,对于现代版本的windows,您可以运行命令行(很像您提到的“像Unix机器等”) 该工具名为FCIV,您可以在此处从Microsoft下载。 运行它非常简单
FCIV -md5 -sha1 C:\path\to\my\file
MD5 SHA1
------------------------------------------------------------------------------------------
8a3d1ae852c3d2f255ea9a732a539721 9747e6afa6d6fcb94fe3bf86ead91683c26d1aca c:\path\to\my\file
我非常确定,在powershell中,您可以将该响应解析为PSObject。这里有一个powershell 1线性程序,如果文件的校验和匹配,它将返回“true”。 只需根据需要替换$filePath、$hash和加密类型
certUtil-hashfile$filePath SHA256 |选择字符串-模式“^.{2}\s”|%{($.-Replace“”,“”)-eq“$hash”}