1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#でバイナリファイルのSHA-256を計算する(実質4行)

Posted at

.NETやっぱり便利

たったこれだけ

sha256test.cs

using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        if (args.Length == 0) { return; }

        byte[] byteValue = File.ReadAllBytes(args[0]);
        SHA256 crypto = new SHA256CryptoServiceProvider();
        byte[] hashValue = crypto.ComputeHash(byteValue);
        Console.WriteLine( String.Join("", hashValue.Select(x=>x.ToString("x2")).ToArray()) );
    }
}

動確

下記のzipに対してSHA256一致確認済み。
https://www.ruby-lang.org/ja/news/2019/10/02/ruby-2-4-9-released/


>sha256test ruby-2.4.9.zip
4ad1c32554319661f2872bb978ff2cd520bc4593681a6476b4c5e7f330172d8b
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?