How do I do a SHA1 File Checksum in C#?

前端 未结 4 1270
鱼传尺愫
鱼传尺愫 2020-11-27 12:45

How do I use the SHA1CryptoServiceProvider() on a file to create a SHA1 Checksum of the file?

4条回答
  •  被撕碎了的回忆
    2020-11-27 13:14

    With the ComputeHash method. See here:

    ComputeHash

    Example snippet:

    using(var cryptoProvider = new SHA1CryptoServiceProvider())
    {
        string hash = BitConverter
                .ToString(cryptoProvider.ComputeHash(buffer));
    
        //do something with hash
    }
    

    Where buffer is the contents of your file.

提交回复
热议问题