System.Security.Cryptography.MD5CryptoServiceProvider

M

Mike

I'm wonder if anyone has tested the
System.Security.Cryptography.MD5CryptoServiceProvider
against the RFC 1321 Test suite?

For example, here is the list of string to hash for md5:
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72

I haven't been able to these result? Has anyone gotten it
to work? If yes, what did you have to do?
 
S

Sébastien Pouliot

They all work.

using System;
using System.Security.Cryptography;
using System.Text;

public class MD5Test {
public static void Main (string[] args)
{
MD5 hash = MD5.Create ();
byte[] data = new byte [0];
byte[] empty = hash.ComputeHash (data);
Console.WriteLine (BitConverter.ToString (empty));

data = Encoding.ASCII.GetBytes ("a");
byte[] a = hash.ComputeHash (data);
Console.WriteLine (BitConverter.ToString (a));

data = Encoding.ASCII.GetBytes ("abc");
byte[] abc = hash.ComputeHash (data);
Console.WriteLine (BitConverter.ToString (abc));
}
}

One common error in using hash with .NET is hashing a unicode string.

Sebastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top