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
解説解説
使用例使用例

dataMD5 ハッシュ値計算して返すコード例次に示します

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 名前空間

その他の技術情報

暗号サービス


このページでは「.NET Framework クラス ライブラリ リファレンス」からMD5CryptoServiceProviderを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMD5CryptoServiceProviderを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMD5CryptoServiceProviderを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MD5CryptoServiceProvider」の関連用語

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

   

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



MD5CryptoServiceProviderのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS