Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MD5 string hashing - via a WCF service

DZone's Guide to

MD5 string hashing - via a WCF service

·
Free Resource

I was working on a Flickr application for Windows Phone 7 and one of the required elements for it was the necessity to generate a signature, that basically is a MD5 hash of a string. Instead of working directly with hashing inside the application, I decided to take this task one level up and set it up as a web service.

So now I have a WCF service that can hash strings, hosted at:

http://services.dennisdel.com/md5/MD5HashService.svc

The services subdomain is there because I plan on working on some more utility services that will together build my own service hub. But for now it is just a WCF sandbox for me.

The service can be called from a .NET application by adding a service reference:

image

Once prompted, just use the service URL I mentioned above:

image

The whole service is built around IHash that has a single method defined – GetHashString:

image

That method returns a hashed string, so in your application you can call it asynchronously like this:

MD5HashService.HashClient client = new MD5HashService.HashClient();
client.GetHashStringCompleted +=
new EventHandler<MD5HashService.GetHashStringCompletedEventArgs>(client_GetHashStringCompleted);
client.GetHashStringAsync("MyString"); 

Note that I am referencing client_GetHashStringCompleted as the event handler that will be triggered when the asynchronous operation is completed. In my case (testing purposes), I simply display the result of the request:

void client_GetHashStringCompleted
(object sender, MD5HashService.GetHashStringCompletedEventArgs e)
{
Debug.WriteLine(e.Result);
} 

That way, you can use this service in your .NET application if you don’t want to manage MD5 string hashing inside your application (e.g. you have a mobile application).

I created this as a “just-for-fun” project, but I would appreciate any feedback regarding this service. Let me know if you encounter any issues or find bugs, and I will try fixing them in a timely manner.

You can download the source code for this service here.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}