0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#でファイルのSHA256ハッシュ値を取得する

0
Posted at

1. はじめに

  • C#でファイルのハッシュ値を取得したい
  • SHA256アルゴリズムを使用して生成したい

2. 開発環境

  • C#
  • .NET 9
  • Visual Studio 2022

3. ソースコード

// TODO: ファイル名
var file = @"C:\XXX.XX";

// ファイルをストリームとして開く
using var stream = File.OpenRead(file);

// ファイルのSHA256ハッシュ値を計算
var hash256Byte = System.Security.Cryptography.SHA256.HashData(stream);

// バイト配列を16進文字列へ変換
var hash256 = Convert.ToHexString(hash256Byte).ToLowerInvariant();

// コンソールへ出力
Console.WriteLine(hash256);

4. 参考文献

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?