zoukankan      html  css  js  c++  java
  • 计算文件的散列值

    介绍一种使用md5计算hash值的方法。 下面的代码分别计算两个文件的散列值并比较两个文件是否相同。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;
    using System.IO;


            static bool fileCompare(string srcFilename, string destFilename)
            {
                try
                {
                    //if file doesn't exist, will throw exception
                    FileInfo srcFile = new FileInfo(srcFilename);
                    FileInfo destFile = new FileInfo(destFilename);
                    MD5 checksumCalculator = MD5.Create();
                    byte[] srcChecksum = checksumCalculator.ComputeHash(srcFile.OpenRead());
                    byte[] destChecksum = checksumCalculator.ComputeHash(destFile.OpenRead());
                    if (srcChecksum.Length != destChecksum.Length)
                        return false;
                    for (int index = 0; index < srcChecksum.Length; index++)
                    {
                        if (srcChecksum[index] != destChecksum[index])
                            return false;
                    }
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                return false;
            }
  • 相关阅读:
    Android studio 搭建测试环境 创建虚拟机
    Halcon算子翻译——break
    Halcon算子翻译——throw
    halcon算子翻译——stop
    halcon算子翻译——return
    halcon算子翻译——par_join
    Halcon算子翻译——import
    Halcon算子翻译——global
    Halcon算子翻译——export_def
    Halcon算子翻译——exit
  • 原文地址:https://www.cnblogs.com/magicdlf/p/1086682.html
Copyright © 2011-2022 走看看