RIPEMD160 Klasa

Definicja

Reprezentuje klasę abstrakcyjną, z której dziedziczą wszystkie implementacje algorytmu skrótu 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
Dziedziczenie
RIPEMD160
Pochodne
Atrybuty

Przykłady

Poniższy przykład kodu oblicza RIPEMD160 skrót dla wszystkich plików w katalogu.

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

Uwagi

Funkcje skrótu mapować ciągi binarne dowolnej długości na małe ciągi binarne o stałej długości. Funkcja skrótu kryptograficznego ma właściwość, którą można obliczać, aby znaleźć dwa odrębne dane wejściowe, które mają wartość skrótu; oznacza to, że skróty dwóch zestawów danych powinny być zgodne, jeśli odpowiednie dane również są zgodne. Niewielkie zmiany w danych powodują duże nieprzewidywalne zmiany skrótu.

RIPEMD-160 to 160-bitowa funkcja skrótu kryptograficznego. Jest przeznaczony do użycia jako zamiennik 128-bitowych funkcji skrótów MD4, MD5 i RIPEMD. RIPEMD został opracowany w ramach projektu UE RIPE (RACE Integrity Primitives Evaluation, 1988-1992).

Uwaga

RIPEMD160 został zastąpiony przez algorytmy Secure Hash Algorithms SHA-256 i SHA-512 oraz ich klasy pochodne. SHA256 i SHA512 oferują lepsze zabezpieczenia i wydajność niż RIPEMD160. Używaj RIPEMD160 tylko w celu zachowania zgodności ze starszymi aplikacjami i danymi.

Konstruktory

RIPEMD160()

Inicjuje nowe wystąpienie klasy RIPEMD160.

Pola

HashSizeValue

Reprezentuje rozmiar w bitach obliczonego kodu skrótu.

(Odziedziczone po HashAlgorithm)
HashValue

Reprezentuje wartość obliczonego kodu skrótu.

(Odziedziczone po HashAlgorithm)
State

Reprezentuje stan obliczeń skrótu.

(Odziedziczone po HashAlgorithm)

Właściwości

CanReuseTransform

Pobiera wartość wskazującą, czy można ponownie użyć bieżącego przekształcenia.

(Odziedziczone po HashAlgorithm)
CanTransformMultipleBlocks

Po zastąpieniu w klasie pochodnej pobiera wartość wskazującą, czy można przekształcić wiele bloków.

(Odziedziczone po HashAlgorithm)
Hash

Pobiera wartość obliczonego kodu skrótu.

(Odziedziczone po HashAlgorithm)
HashSize

Pobiera rozmiar w bitach obliczonego kodu skrótu.

(Odziedziczone po HashAlgorithm)
InputBlockSize

Po przesłonięciu w klasie pochodnej pobiera rozmiar bloku wejściowego.

(Odziedziczone po HashAlgorithm)
OutputBlockSize

Po zastąpieniu w klasie pochodnej pobiera rozmiar bloku wyjściowego.

(Odziedziczone po HashAlgorithm)

Metody

Clear()

Zwalnia wszystkie zasoby używane przez klasę HashAlgorithm .

(Odziedziczone po HashAlgorithm)
ComputeHash(Byte[])

Oblicza wartość skrótu dla określonej tablicy bajtów.

(Odziedziczone po HashAlgorithm)
ComputeHash(Byte[], Int32, Int32)

Oblicza wartość skrótu dla określonego regionu określonej tablicy bajtów.

(Odziedziczone po HashAlgorithm)
ComputeHash(Stream)

Oblicza wartość skrótu dla określonego Stream obiektu.

(Odziedziczone po HashAlgorithm)
ComputeHashAsync(Stream, CancellationToken)

Asynchronicznie oblicza wartość skrótu dla określonego Stream obiektu.

(Odziedziczone po HashAlgorithm)
Create()

Tworzy wystąpienie domyślnej implementacji algorytmu skrótu RIPEMD160 .

Create(String)

Tworzy wystąpienie określonej implementacji algorytmu skrótu RIPEMD160 .

Dispose()

Zwalnia wszystkie zasoby używane przez bieżące wystąpienie klasy HashAlgorithm.

(Odziedziczone po HashAlgorithm)
Dispose(Boolean)

Zwalnia zasoby niezarządzane używane przez element HashAlgorithm i opcjonalnie zwalnia zasoby zarządzane.

(Odziedziczone po HashAlgorithm)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
HashCore(Byte[], Int32, Int32)

Po przesłonięciu w klasie pochodnej dane są przesyłane do obiektu do algorytmu skrótu do obliczania skrótu.

(Odziedziczone po HashAlgorithm)
HashCore(ReadOnlySpan<Byte>)

Kieruje dane zapisywane do obiektu w algorytmie skrótu na potrzeby obliczania skrótu.

(Odziedziczone po HashAlgorithm)
HashFinal()

Po zastąpieniu w klasie pochodnej finalizuje obliczenia skrótu po przetworzeniu ostatnich danych przez algorytm skrótu kryptograficznego.

(Odziedziczone po HashAlgorithm)
Initialize()

Resetuje algorytm skrótu do stanu początkowego.

(Odziedziczone po HashAlgorithm)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)
TransformBlock(Byte[], Int32, Int32, Byte[], Int32)

Oblicza wartość skrótu dla określonego regionu tablicy bajtów wejściowych i kopiuje określony region tablicy bajtów wejściowych do określonego regionu tablicy bajtów wyjściowych.

(Odziedziczone po HashAlgorithm)
TransformFinalBlock(Byte[], Int32, Int32)

Oblicza wartość skrótu dla określonego regionu określonej tablicy bajtów.

(Odziedziczone po HashAlgorithm)
TryComputeHash(ReadOnlySpan<Byte>, Span<Byte>, Int32)

Próbuje obliczyć wartość skrótu dla określonej tablicy bajtów.

(Odziedziczone po HashAlgorithm)
TryHashFinal(Span<Byte>, Int32)

Próbuje sfinalizować obliczanie skrótu po przetworzeniu ostatnich danych przez algorytm skrótu.

(Odziedziczone po HashAlgorithm)

Jawne implementacje interfejsu

IDisposable.Dispose()

Zwalnia zasoby niezarządzane używane przez element HashAlgorithm i opcjonalnie zwalnia zasoby zarządzane.

(Odziedziczone po HashAlgorithm)

Dotyczy

Zobacz też