RIPEMD160.Create Method

Definition

Creates specific implementations of the RIPEMD160 class.

Overloads

Create()

Creates an instance of the default implementation of the RIPEMD160 hash algorithm.

Create(String)

Creates an instance of the specified implementation of the RIPEMD160 hash algorithm.

Create()

Creates an instance of the default implementation of the RIPEMD160 hash algorithm.

C#
public static System.Security.Cryptography.RIPEMD160 Create();

Returns

A new instance of the RIPEMD160 hash algorithm.

Exceptions

The algorithm was used with Federal Information Processing Standards (FIPS) mode enabled, but it is not FIPS-compatible.

Examples

The following code example calculates the RIPEMD160 hash for all files in a directory.

C#
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();
    }
}

Remarks

You cannot create an instance of an abstract class. Application code will create a new instance of a derived class. For more information, see the RIPEMD160Managed class.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Create(String)

Creates an instance of the specified implementation of the RIPEMD160 hash algorithm.

C#
public static System.Security.Cryptography.RIPEMD160 Create(string hashName);

Parameters

hashName
String

The name of the specific implementation of RIPEMD160 to use.

Returns

A new instance of the specified implementation of RIPEMD160.

Exceptions

The algorithm described by the hashName parameter was used with Federal Information Processing Standards (FIPS) mode enabled, but it is not FIPS-compatible.

Remarks

You cannot create an instance of an abstract class. Application code will create a new instance of a derived class. For more information, see the RIPEMD160Managed class.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1