Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8895

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

$
0
0

.NETやっぱり便利

たったこれだけ

sha256test.cs
usingSystem;usingSystem.IO;usingSystem.Linq;usingSystem.Security.Cryptography;classProgram{[STAThread]staticvoidMain(string[]args){if(args.Length==0){return;}byte[]byteValue=File.ReadAllBytes(args[0]);SHA256crypto=newSHA256CryptoServiceProvider();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

Viewing all articles
Browse latest Browse all 8895

Trending Articles