Create Method
Collapse the table of content
Expand the table of content

RIPEMD160.Create Method ()


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

Namespace:   System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

public static RIPEMD160 Create()

Return Value

Type: System.Security.Cryptography.RIPEMD160

A new instance of the RIPEMD160 hash algorithm.

Exception Condition

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

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.

Legacy Code Example

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

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

public class HashDirectory

    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;
                Console.WriteLine("No directory selected.");
            directory = args[0];
            // 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.
                // Close the file.
        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(" ");

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft