MD5CryptoServiceProviderとは? わかりやすく解説

MD5CryptoServiceProvider クラス

暗号化サービス プロバイダ (CSP: cryptographic service provider) によって提供された実装を使用して、入力データの MD5 ハッシュ値を計算します。このクラスは継承できません。

名前空間: System.Security.Cryptography
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public NotInheritable Class
 MD5CryptoServiceProvider
    Inherits MD5
Dim instance As MD5CryptoServiceProvider
[ComVisibleAttribute(true)] 
public sealed class MD5CryptoServiceProvider
 : MD5
[ComVisibleAttribute(true)] 
public ref class MD5CryptoServiceProvider sealed
 : public MD5
/** @attribute ComVisibleAttribute(true) */ 
public final class MD5CryptoServiceProvider
 extends MD5
ComVisibleAttribute(true) 
public final class MD5CryptoServiceProvider
 extends MD5
解説解説
使用例使用例

data の MD5 ハッシュ値を計算して返すコード例を次に示します。

Function MD5hash(data() As Byte)
 As Byte()
    ' This is one implementation of the abstract class MD5.
    Dim md5 As New MD5CryptoServiceProvider()
       
    Dim result As Byte()
 = md5.ComputeHash(data)
       
    Return result
End Function
byte[] MD5hash (byte[] data)
 {
    // This is one implementation of the abstract class MD5.
    MD5 md5 = new MD5CryptoServiceProvider();

    byte[] result = md5.ComputeHash(data);

    return result;
 }
private:
   array<Byte>^ MD5hash( array<Byte>^data )
   {
      // This is one implementation of the abstract class MD5.
      MD5^ md5 = gcnew MD5CryptoServiceProvider;

      array<Byte>^ result = md5->ComputeHash( data );

      return result;
   }
ubyte[] MD5hash(ubyte data[])
{
    // This is one implementation of the abstract class MD5.
    MD5 md5 = new MD5CryptoServiceProvider();
    ubyte result[] = md5.ComputeHash(data);
    return result;
} //MD5hash

文字列の MD5 ハッシュ値を計算し、32 文字の 16 進形式の文字列としてハッシュを返すコード例を次に示します。このコード例で作成されるハッシュ文字列は、32 文字の 16 進形式のハッシュ文字列を作成する (任意のプラットフォーム上の) MD5 ハッシュ関数と互換性があります。

Imports System
Imports System.Security.Cryptography
Imports System.Text

Module Example

    ' Hash an input string and return the hash as
    ' a 32 character hexadecimal string.
    Function getMd5Hash(ByVal input As
 String) As String
        ' Create a new instance of the MD5CryptoServiceProvider object.
        Dim md5Hasher As New
 MD5CryptoServiceProvider()

        ' Convert the input string to a byte array and compute the hash.
        Dim data As Byte()
 = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))

        ' Create a new Stringbuilder to collect the bytes
        ' and create a string.
        Dim sBuilder As New
 StringBuilder()

        ' Loop through each byte of the hashed data 
        ' and format each one as a hexadecimal string.
        Dim i As Integer
        For i = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next i

        ' Return the hexadecimal string.
        Return sBuilder.ToString()

    End Function


    ' Verify a hash against a string.
    Function verifyMd5Hash(ByVal input As
 String, ByVal hash As
 String) As Boolean
        ' Hash the input.
        Dim hashOfInput As String
 = getMd5Hash(input)

        ' Create a StringComparer an comare the hashes.
        Dim comparer As StringComparer = StringComparer.OrdinalIgnoreCase

        If 0 = comparer.Compare(hashOfInput, hash) Then
            Return True
        Else
            Return False
        End If

    End Function



    Sub Main()
        Dim source As String
 = "Hello World!"

        Dim hash As String
 = getMd5Hash(source)

        Console.WriteLine("The MD5 hash of " + source
 + " is: " + hash + ".")

        Console.WriteLine("Verifying the hash...")

        If verifyMd5Hash(source, hash) Then
            Console.WriteLine("The hashes are the same.")
        Else
            Console.WriteLine("The hashes are not same.")
        End If

    End Sub
End Module
' This code example produces the following output:
'
' The MD5 hash of Hello World! is: ed076287532e86365e841e92bfc50d8c.
' Verifying the hash...
' The hashes are the same.
using System;
using System.Security.Cryptography;
using System.Text;

class Example
{
    // Hash an input string and return the hash as
    // a 32 character hexadecimal string.
    static string getMd5Hash(string
 input)
    {
        // Create a new instance of the MD5CryptoServiceProvider object.
        MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

        // Convert the input string to a byte array and compute the
 hash.
        byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

        // Create a new Stringbuilder to collect the bytes
        // and create a string.
        StringBuilder sBuilder = new StringBuilder();

        // Loop through each byte of the hashed data 
        // and format each one as a hexadecimal string.
        for (int i = 0; i < data.Length;
 i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }

        // Return the hexadecimal string.
        return sBuilder.ToString();
    }

    // Verify a hash against a string.
    static bool verifyMd5Hash(string
 input, string hash)
    {
        // Hash the input.
        string hashOfInput = getMd5Hash(input);

        // Create a StringComparer an comare the hashes.
        StringComparer comparer = StringComparer.OrdinalIgnoreCase;

        if (0 == comparer.Compare(hashOfInput, hash))
        {
            return true;
        }
        else
        {
            return false;
        }
    }


    static void Main()
    {
        string source = "Hello World!";
        
        string hash = getMd5Hash(source);

        Console.WriteLine("The MD5 hash of " + source + " is: "
 + hash + ".");

        Console.WriteLine("Verifying the hash...");

        if (verifyMd5Hash(source, hash))
        {
            Console.WriteLine("The hashes are the same.");
        }
        else
        {
            Console.WriteLine("The hashes are not same.");
        }
        
    }
}
// This code example produces the following output:
//
// The MD5 hash of Hello World! is: ed076287532e86365e841e92bfc50d8c.
// Verifying the hash...
// The hashes are the same.
継承階層継承階層
System.Object
   System.Security.Cryptography.HashAlgorithm
     System.Security.Cryptography.MD5
      System.Security.Cryptography.MD5CryptoServiceProvider
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MD5CryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

MD5CryptoServiceProvider コンストラクタ


MD5CryptoServiceProvider フィールド


プロテクト フィールドプロテクト フィールド

  名前 説明
プロテクト フィールド HashSizeValue  計算されたハッシュ コードのサイズをビット単位で表します。 ( HashAlgorithm から継承されます。)
プロテクト フィールド HashValue  計算されたハッシュ コードの値を表します。 ( HashAlgorithm から継承されます。)
プロテクト フィールド State  ハッシュ計算の状態を表します。 ( HashAlgorithm から継承されます。)
参照参照

関連項目

MD5CryptoServiceProvider クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

MD5CryptoServiceProvider プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CanReuseTransform  現在の変換を再利用できるかどうかを示す値を取得します。 ( HashAlgorithm から継承されます。)
パブリック プロパティ CanTransformMultipleBlocks  派生クラスでオーバーライドされると、複数のブロックを変換できるかどうかを示す値を取得します。 ( HashAlgorithm から継承されます。)
パブリック プロパティ Hash  計算されたハッシュ コードの値を取得します。 ( HashAlgorithm から継承されます。)
パブリック プロパティ HashSize  計算されたハッシュ コードのサイズをビット単位で取得します。 ( HashAlgorithm から継承されます。)
パブリック プロパティ InputBlockSize  派生クラスでオーバーライドされると、入力ブロック サイズを取得します。 ( HashAlgorithm から継承されます。)
パブリック プロパティ OutputBlockSize  派生クラスでオーバーライドされると、出力ブロック サイズを取得します。 ( HashAlgorithm から継承されます。)
参照参照

関連項目

MD5CryptoServiceProvider クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

MD5CryptoServiceProvider メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Clear  HashAlgorithm クラスによって使用されているすべてのリソースを解放します。 ( HashAlgorithm から継承されます。)
パブリック メソッド ComputeHash  オーバーロードされます。 入力データのハッシュ値を計算します。 ( HashAlgorithm から継承されます。)
パブリック メソッド Create  オーバーロードされます。 この抽象クラスの特定の実装を作成できるようにします。 ( MD5 から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド Initialize オーバーライドされます。 MD5CryptoServiceProvider のインスタンスを初期化します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
パブリック メソッド TransformBlock  入力バイト配列の指定した領域のハッシュ値を計算し、結果ハッシュ値を出力バイト配列の指定した領域にコピーします。 ( HashAlgorithm から継承されます。)
パブリック メソッド TransformFinalBlock  指定したバイト配列の指定した領域のハッシュ値を計算します。 ( HashAlgorithm から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MD5CryptoServiceProvider クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

MD5CryptoServiceProvider メンバ

暗号化サービス プロバイダ (CSP: cryptographic service provider) によって提供された実装を使用して、入力データの MD5 ハッシュ値を計算します。このクラスは継承できません。

MD5CryptoServiceProvider データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド MD5CryptoServiceProvider MD5CryptoServiceProvider クラスの新しいインスタンスを初期化します。
プロテクト フィールドプロテクト フィールド
  名前 説明
プロテクト フィールド HashSizeValue  計算されたハッシュ コードのサイズをビット単位で表します。(HashAlgorithm から継承されます。)
プロテクト フィールド HashValue  計算されたハッシュ コードの値を表します。(HashAlgorithm から継承されます。)
プロテクト フィールド State  ハッシュ計算の状態を表します。(HashAlgorithm から継承されます。)
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CanReuseTransform  現在の変換を再利用できるかどうかを示す値を取得します。(HashAlgorithm から継承されます。)
パブリック プロパティ CanTransformMultipleBlocks  派生クラスでオーバーライドされると、複数のブロックを変換できるかどうかを示す値を取得します。(HashAlgorithm から継承されます。)
パブリック プロパティ Hash  計算されたハッシュ コードの値を取得します。(HashAlgorithm から継承されます。)
パブリック プロパティ HashSize  計算されたハッシュ コードのサイズをビット単位で取得します。(HashAlgorithm から継承されます。)
パブリック プロパティ InputBlockSize  派生クラスでオーバーライドされると、入力ブロック サイズを取得します。(HashAlgorithm から継承されます。)
パブリック プロパティ OutputBlockSize  派生クラスでオーバーライドされると、出力ブロック サイズを取得します。(HashAlgorithm から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Clear  HashAlgorithm クラスによって使用されているすべてのリソースを解放します。 (HashAlgorithm から継承されます。)
パブリック メソッド ComputeHash  オーバーロードされます。 入力データのハッシュ値を計算します。 (HashAlgorithm から継承されます。)
パブリック メソッド Create  オーバーロードされます。 この抽象クラスの特定の実装を作成できるようにします。 (MD5 から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド Initialize オーバーライドされます。 MD5CryptoServiceProvider のインスタンスを初期化します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
パブリック メソッド TransformBlock  入力バイト配列の指定した領域のハッシュ値を計算し、結果ハッシュ値を出力バイト配列の指定した領域にコピーします。 (HashAlgorithm から継承されます。)
パブリック メソッド TransformFinalBlock  指定したバイト配列の指定した領域のハッシュ値を計算します。 (HashAlgorithm から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MD5CryptoServiceProvider クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「MD5CryptoServiceProvider」の関連用語

MD5CryptoServiceProviderのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MD5CryptoServiceProviderのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS