RIPEMD160 クラス

定義

MD160 ハッシュ アルゴリズムのすべての実装が継承する、抽象クラスを表します。

public ref class RIPEMD160 abstract : System::Security::Cryptography::HashAlgorithm
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class RIPEMD160 : System.Security.Cryptography.HashAlgorithm
[<System.Runtime.InteropServices.ComVisible(true)>]
type RIPEMD160 = class
    inherit HashAlgorithm
Public MustInherit Class RIPEMD160
Inherits HashAlgorithm
継承
RIPEMD160
派生
属性

次のコード例では、ディレクトリ内のすべてのファイルの RIPEMD160 ハッシュを計算します。

using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;

// Print the byte array in a readable format.
void PrintByteArray( array<Byte>^array )
{
   int i;
   for ( i = 0; i < array->Length; i++ )
   {
      Console::Write( String::Format( "{0:X2}", array[ i ] ) );
      if ( (i % 4) == 3 )
            Console::Write( " " );

   }
   Console::WriteLine();
}

int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   if ( args->Length < 2 )
   {
      Console::WriteLine( "Usage: hashdir <directory>" );
      return 0;
   }

   try
   {
      
      // Create a DirectoryInfo object representing the specified directory.
      DirectoryInfo^ dir = gcnew DirectoryInfo( args[ 1 ] );
      
      // Get the FileInfo objects for every file in the directory.
      array<FileInfo^>^files = dir->GetFiles();
      
      // Initialize a RIPE160 hash object.
      RIPEMD160 ^ myRIPEMD160 = RIPEMD160Managed::Create();
      array<Byte>^hashValue;
      
      // Compute and print the hash values for each file in directory.
      System::Collections::IEnumerator^ myEnum = files->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         FileInfo^ fInfo = safe_cast<FileInfo^>(myEnum->Current);
         
         // Create a fileStream for the file.
         FileStream^ fileStream = fInfo->Open( FileMode::Open );
         
         // Compute the hash of the fileStream.
         hashValue = myRIPEMD160->ComputeHash( fileStream );
         
         // Write the name of the file to the Console.
         Console::Write( "{0}: ", fInfo->Name );
         
         // Write the hash value to the Console.
         PrintByteArray( hashValue );
         
         // Close the file.
         fileStream->Close();
      }
      return 0;
   }
   catch ( DirectoryNotFoundException^ ) 
   {
      Console::WriteLine( "Error: The directory specified could not be found." );
   }
   catch ( IOException^ ) 
   {
      Console::WriteLine( "Error: A file in the directory could not be accessed." );
   }

}
using System;
using System.IO;
using System.Security.Cryptography;
using System.Windows.Forms;

public class HashDirectory
{

    [STAThreadAttribute]
    public static void Main(String[] args)
    {
        string directory = "";
        if (args.Length < 1)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult dr = fbd.ShowDialog();
            if (dr == DialogResult.OK)
            {
                directory = fbd.SelectedPath;
            }
            else
            {
                Console.WriteLine("No directory selected.");
                return;
            }
        }
        else
        {
            directory = args[0];
        }

        try
        {
            // Create a DirectoryInfo object representing the specified directory.
            DirectoryInfo dir = new DirectoryInfo(directory);
            // Get the FileInfo objects for every file in the directory.
            FileInfo[] files = dir.GetFiles();
            // Initialize a RIPE160 hash object.
            RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
            byte[] hashValue;
            // Compute and print the hash values for each file in directory.
            foreach (FileInfo fInfo in files)
            {
                // Create a fileStream for the file.
                FileStream fileStream = fInfo.Open(FileMode.Open);
                // Be sure it's positioned to the beginning of the stream.
                fileStream.Position = 0;
                // Compute the hash of the fileStream.
                hashValue = myRIPEMD160.ComputeHash(fileStream);
                // Write the name of the file to the Console.
                Console.Write(fInfo.Name + ": ");
                // Write the hash value to the Console.
                PrintByteArray(hashValue);
                // Close the file.
                fileStream.Close();
            }
            return;
        }
        catch (DirectoryNotFoundException)
        {
            Console.WriteLine("Error: The directory specified could not be found.");
        }
        catch (IOException)
        {
            Console.WriteLine("Error: A file in the directory could not be accessed.");
        }
    }
    // Print the byte array in a readable format.
    public static void PrintByteArray(byte[] array)
    {
        int i;
        for (i = 0; i < array.Length; i++)
        {
            Console.Write(String.Format("{0:X2}", array[i]));
            if ((i % 4) == 3) Console.Write(" ");
        }
        Console.WriteLine();
    }
}
Imports System.IO
Imports System.Security.Cryptography
Imports System.Windows.Forms

Public Class HashDirectory

    Public Shared Sub Main(ByVal args() As String)
        Dim directory As String
        If args.Length < 1 Then
            Dim fdb As New FolderBrowserDialog
            Dim dr As DialogResult = fdb.ShowDialog()
            If (dr = DialogResult.OK) Then
                directory = fdb.SelectedPath
            Else
                Console.WriteLine("No directory selected")
                Return
            End If
        Else
            directory = args(0)
        End If
        Try
            ' Create a DirectoryInfo object representing the specified directory.
            Dim dir As New DirectoryInfo(directory)
            ' Get the FileInfo objects for every file in the directory.
            Dim files As FileInfo() = dir.GetFiles()
            ' Initialize a RIPE160 hash object.
            Dim myRIPEMD160 As RIPEMD160 = RIPEMD160Managed.Create()
            Dim hashValue() As Byte
            ' Compute and print the hash values for each file in directory.
            Dim fInfo As FileInfo
            For Each fInfo In files
                ' Create a fileStream for the file.
                Dim fileStream As FileStream = fInfo.Open(FileMode.Open)
                ' Be sure it's positioned to the beginning of the stream.
                fileStream.Position = 0
                ' Compute the hash of the fileStream.
                hashValue = myRIPEMD160.ComputeHash(fileStream)
                ' Write the name of the file to the Console.
                Console.Write(fInfo.Name + ": ")
                ' Write the hash value to the Console.
                PrintByteArray(hashValue)
                ' Close the file.
                fileStream.Close()
            Next fInfo
            Return
        Catch DExc As DirectoryNotFoundException
            Console.WriteLine("Error: The directory specified could not be found.")
        Catch IOExc As IOException
            Console.WriteLine("Error: A file in the directory could not be accessed.")
        End Try

    End Sub

    ' Print the byte array in a readable format.
    Public Shared Sub PrintByteArray(ByVal array() As Byte)
        Dim i As Integer
        For i = 0 To array.Length - 1
            Console.Write(String.Format("{0:X2}", array(i)))
            If i Mod 4 = 3 Then
                Console.Write(" ")
            End If
        Next i
        Console.WriteLine()

    End Sub
End Class

注釈

ハッシュ関数は、任意の長さのバイナリ文字列を固定長の小さなバイナリ文字列にマップします。 暗号化ハッシュ関数には、同じ値にハッシュする 2 つの個別の入力を見つけることが不可能なプロパティがあります。つまり、対応するデータも一致する場合は、2 つのデータ セットのハッシュが一致する必要があります。 データを小さく変更すると、ハッシュに大きな予期しない変更が発生します。

RIPEMD-160 は、160 ビット暗号化ハッシュ関数です。 これは、128 ビット ハッシュ関数 MD4、MD5、RIPEMD の代わりに使用することを目的としています。 RIPEMD は、EU プロジェクト RIPE (RACE Integrity Primitives Evaluation, 1988-1992) のフレームワークで開発されました。

Note

RIPEMD160 は、セキュリティで保護されたハッシュ アルゴリズム SHA-256 と SHA-512 とその派生クラスに置き換えられます。 SHA256 より SHA512 優れたセキュリティとパフォーマンスを RIPEMD160提供します。 レガシ アプリケーションとデータとの互換性のためにのみ使用 RIPEMD160 します。

コンストラクター

RIPEMD160()

RIPEMD160 クラスの新しいインスタンスを初期化します。

フィールド

HashSizeValue

計算されたハッシュ コードのサイズをビット単位で表します。

(継承元 HashAlgorithm)
HashValue

計算されたハッシュ コードの値を表します。

(継承元 HashAlgorithm)
State

ハッシュ計算の状態を表します。

(継承元 HashAlgorithm)

プロパティ

CanReuseTransform

現在の変換を再利用できるかどうかを示す値を取得します。

(継承元 HashAlgorithm)
CanTransformMultipleBlocks

派生クラスでオーバーライドされると、複数のブロックを変換できるかどうかを示す値を取得します。

(継承元 HashAlgorithm)
Hash

計算されたハッシュ コードの値を取得します。

(継承元 HashAlgorithm)
HashSize

計算されたハッシュ コードのサイズをビット単位で取得します。

(継承元 HashAlgorithm)
InputBlockSize

派生クラスでオーバーライドされると、入力ブロック サイズを取得します。

(継承元 HashAlgorithm)
OutputBlockSize

派生クラスでオーバーライドされると、出力ブロック サイズを取得します。

(継承元 HashAlgorithm)

メソッド

Clear()

HashAlgorithm クラスによって使用されているすべてのリソースを解放します。

(継承元 HashAlgorithm)
ComputeHash(Byte[])

指定したバイト配列のハッシュ値を計算します。

(継承元 HashAlgorithm)
ComputeHash(Byte[], Int32, Int32)

指定したバイト配列の指定した領域のハッシュ値を計算します。

(継承元 HashAlgorithm)
ComputeHash(Stream)

指定された Stream オブジェクトのハッシュ値を計算します。

(継承元 HashAlgorithm)
ComputeHashAsync(Stream, CancellationToken)

指定された Stream オブジェクトのハッシュ値を非同期に計算します。

(継承元 HashAlgorithm)
Create()

RIPEMD160 ハッシュ アルゴリズムの既定の実装のインスタンスを作成します。

Create(String)

RIPEMD160 ハッシュ アルゴリズムの指定された実装のインスタンスを作成します。

Dispose()

HashAlgorithm クラスの現在のインスタンスによって使用されているすべてのリソースを解放します。

(継承元 HashAlgorithm)
Dispose(Boolean)

HashAlgorithm によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 HashAlgorithm)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
HashCore(Byte[], Int32, Int32)

派生クラスでオーバーライドされると、ハッシュを計算するために、オブジェクトに書き込まれたデータをハッシュ アルゴリズムにルーティングします。

(継承元 HashAlgorithm)
HashCore(ReadOnlySpan<Byte>)

ハッシュを計算するために、オブジェクトに書き込んだデータをハッシュ アルゴリズムにルーティングします。

(継承元 HashAlgorithm)
HashFinal()

派生クラスでオーバーライドされると、暗号化ハッシュ アルゴリズムによって最後のデータが処理された後に、ハッシュ計算を終了します。

(継承元 HashAlgorithm)
Initialize()

ハッシュ アルゴリズムを初期状態にリセットします。

(継承元 HashAlgorithm)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
TransformBlock(Byte[], Int32, Int32, Byte[], Int32)

入力バイト配列の指定した領域のハッシュ値を計算し、入力バイト配列の指定した領域を出力バイト配列の指定した領域にコピーします。

(継承元 HashAlgorithm)
TransformFinalBlock(Byte[], Int32, Int32)

指定したバイト配列の指定した領域のハッシュ値を計算します。

(継承元 HashAlgorithm)
TryComputeHash(ReadOnlySpan<Byte>, Span<Byte>, Int32)

指定したバイト配列のハッシュ値の計算を試みます。

(継承元 HashAlgorithm)
TryHashFinal(Span<Byte>, Int32)

ハッシュ アルゴリズムによって最後のデータが処理された後、ハッシュ計算の終了を試みます。

(継承元 HashAlgorithm)

明示的なインターフェイスの実装

IDisposable.Dispose()

HashAlgorithm によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 HashAlgorithm)

適用対象

こちらもご覧ください