RIPEMD160Managed 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用托管库计算输入数据的 RIPEMD160 哈希值。
public ref class RIPEMD160Managed : System::Security::Cryptography::RIPEMD160[System.Runtime.InteropServices.ComVisible(true)]
public class RIPEMD160Managed : System.Security.Cryptography.RIPEMD160[<System.Runtime.InteropServices.ComVisible(true)>]
type RIPEMD160Managed = class
    inherit RIPEMD160Public Class RIPEMD160Managed
Inherits RIPEMD160- 继承
- 属性
示例
下面的代码示例演示如何使用 类对文件进行 RIPEMD160Managed 编码,然后如何解码文件。
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
注解
RIPEMD-160 是一个 160 位加密哈希函数。 它旨在用作 128 位哈希函数 MD4、MD5 和 RIPEMD 的安全替代。 RIPEMD 是在欧盟项目 RIPE (RACE 完整性基元评估(1988-1992) )的框架下开发的。
注意
RIPEMD160Managed 已由安全哈希算法 SHA-256 和 SHA-512 及其派生类取代。 SHA256Managed 和 SHA512Managed 提供比 RIPEMD160Managed更好的安全性和性能。 仅用于 RIPEMD160Managed 与旧版应用程序和数据的兼容性。
构造函数
| RIPEMD160Managed() | 初始化 RIPEMD160 类的新实例。 | 
字段
| HashSizeValue | 表示计算所得的哈希代码的大小(以位为单位)。(继承自 HashAlgorithm) | 
| HashValue | 表示计算所得的哈希代码的值。(继承自 HashAlgorithm) | 
| State | 表示哈希计算的状态。(继承自 HashAlgorithm) | 
属性
| CanReuseTransform | 获取一个值,该值指示是否可重复使用当前转换。(继承自 HashAlgorithm) | 
| CanTransformMultipleBlocks | 当在派生类中重写时,获取一个值,该值指示是否可以转换多个块。(继承自 HashAlgorithm) | 
| Hash | 获取计算所得的哈希代码的值。(继承自 HashAlgorithm) | 
| HashSize | 获取计算所得的哈希代码的大小(以位为单位)。(继承自 HashAlgorithm) | 
| InputBlockSize | 当在派生类中重写时,获取输入块的大小。(继承自 HashAlgorithm) | 
| OutputBlockSize | 当在派生类中重写时,获取输出块的大小。(继承自 HashAlgorithm) | 
方法
显式接口实现
| IDisposable.Dispose() | 释放由 HashAlgorithm 占用的非托管资源,还可以另外再释放托管资源。(继承自 HashAlgorithm) |