LoginSignup
7
6

More than 5 years have passed since last update.

MD5のハッシュ値を計算する

Posted at

MD5のハッシュを計算するには、次の名前空間を使用します。

using System.Security.Cryptography;

計算はMD5.ComputeHash( )で行います。オーバーロードは主にbyte[ ]またはStreamです。

static string Run( string path )
{
    var md5 = MD5.Create( );
    using ( var stream = File.OpenRead( path ) )
    {
        return string.Concat(
            md5.ComputeHash( stream )
            .Select( x => string.Format( "{0:x2}", x ) )
        );
    }
}

このサンプルコードの返却値は下記のような感じになります。
2c99a6cd27f781f6862f98e1841b829c

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