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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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 名前空間
その他の技術情報
暗号サービス


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

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

辞書ショートカット

すべての辞書の索引

「MD5CryptoServiceProvider クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS