RipeMD-160


This chapter illustrates how to create RipeMD-160 hashing in C# and VB.NET using the NCiphers.Crypto library.

Table of contents

1. Digest output
2. digest from a byte array
3. digest from a String
4. digest from a file
5. digest from a Stream

1. Digest output

The raw digest output from this hash function is a 160 bits (20 bytes) long byte array constructed by computing the hash algorithm over the input data:

C# example

byte[] hash = NCiphers.Hashing.HashTools.RipeMD160(data);
VB.NET example
 
Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160(data)

There may be cases when we need the digest to be received as a String from the hexadecimal representation of the hash bytes. In that case we shall use:

C# example

byte[] hash = NCiphers.Hashing.HashTools.RipeMD160Hex(data);

VB.NET example

Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160Hex(data)

Back to ToC

2. RipeMD160 from a byte array

Here is how to compute the RipeMD160 message digest of a byte array:

C# example

byte[] data = new byte[] {1,2,3,4,5,6,7,8,9,100,200,300,400,500};
byte[] hash = NCiphers.Hashing.HashTools.RipeMD160(data);
string hashAsString = NCiphers.Hashing.HashTools.RipeMD160Hex(data);

VB.NET example

Dim data As New Byte() {1,2,3,4,5,6,7,8,9,100,200,300,400,500}
Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160(data)
Dim hashAsString As String = NCiphers.Hashing.HashTools.RipeMD160Hex(data)

Back to ToC

3. RipeMD160 from a String

Getting the RipeMD160 hash of a String is similar to the above example:

C# example

string data = "Hello World";
byte[] hash = NCiphers.Hashing.HashTools.RipeMD160(data);
string hashAsString = NCiphers.Hashing.HashTools.RipeMD160Hex(data);

VB.NET example

Dim data As String = "Hello World"
Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160(data)
Dim hashAsString As String = NCiphers.Hashing.HashTools.RipeMD160Hex(data)

Back to ToC

4. RipeMD160 from a file

To get the RipeMD160 hash of a file, we simply supply a System.IO.FileInfo object as parameter:

C# example

System.IO.FileInfo data = new System.IO.FileInfo(@"c:\myfile.txt");
byte[] hash = NCiphers.Hashing.HashTools.RipeMD160(data);
string hashAsString = NCiphers.Hashing.HashTools.RipeMD160Hex(data);

VB.NET example

Dim data As New System.IO.FileInfo("c:\myfile.txt")
Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160(data)
Dim hashAsString As String = NCiphers.Hashing.HashTools.RipeMD160Hex(data)

Back to ToC

5. RipeMD160 from a Stream

The overloaded methods that accept System.IO.Stream parameter, are reading the input byte by byte and compute the RipeMD160 digest over this data. Of course the caller must ensure that the Stream is positioned at the start of the data and after the method call its position will be at the end of the Stream. It is also the obligation of the caller to close the Stream.

C# example

byte[] bytes = new byte[] {1,2,3,4,5,6,7,8,9,100,200,300,400,500};
System.IO.Stream data = new MemoryStream(bytes);
byte[] hash = NCiphers.Hashing.HashTools.RipeMD160(data);
string hashAsString = NCiphers.Hashing.HashTools.RipeMD160Hex(data);

VB.NET example

Dim bytes As New Byte() {1,2,3,4,5,6,7,8,9,100,200,300,400,500}
Dim data As New System.IO.MemoryStream(bytes)
Dim hash As Byte() = NCiphers.Hashing.HashTools.RipeMD160(data)
Dim hashAsString As String = NCiphers.Hashing.HashTools.RipeMD160Hex(data)

Back to ToC

6. Summary

This article demonstrated how to compute RipeMD160 message digest hashes with the NCiphers.Crypto library. Probably you may be interested to see also the other hash functions offered by the library.

List of methods used:

  1. NCiphers.Hashing.HashTools.RipeMD160 – returns the RipeMD160 hash as byte array
  2. NCiphers.Hashing.HashTools.RipeMD160Hex – returns the RipeMD160 hash as hexadecimal String