windows - 如何在 Windows 上执行校验和?

标签 windows

有没有办法像在 unix/linux 机器上一样在 windows 机器上执行校验和?

我无法下载任何第 3 方工具,想知道本地是否有类似的东西?

最佳答案

您可以获得文件的 MD5 哈希值。您基本上会解析文件并将其作为字符串传递给此函数。例如

 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;
    }

(取自here)

...或作为文件:

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();
}

取自here计算文件的MD5校验和

关于windows - 如何在 Windows 上执行校验和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523924/

相关文章:

php - 是否可以在 Windows 中使用 PHP 访问和设置 "File is ready for archiving"标志?

javascript - 无法从手机加载Ionic项目

windows - 在 Win32 应用程序中使用 Windows 窗体

c - getche 按 Enter 后清除屏幕

c++ - ldap_set_option() 未设置选项 "LDAP_OPT_SSL"

c# - 需要使用C#刷新chrome浏览器

sql - 在不知道机器主机名的情况下在 SQL 脚本中指定 Windows 用户名

ruby - 无法让 cucumber 在 Windows 下使用 Ruby 2.x

c - 将参数传递给我的 lua dll 函数

c++ - 如何使用 Visual Studio 为 windows 编译 GMP