Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How expensive is MD5 generation in .NET?

To interact with an external data feed I need to pass a rolling security key which has been MD5 hashed (every day we need to generate a new MD5 hashed key).

I'm trading up whether or not to do it every time we call the external feed or not. I need to has a string of about 10 characters for the feed.

It's for an ASP.NET (C#/ .NET 3.5) site and the feed is used on pretty much every page. Would I best off generating the hash once a day and then storing it in the application cache, and taking the memory hit, or generating it on each request?

like image 664
Aaron Powell Avatar asked Jan 07 '09 05:01

Aaron Powell


People also ask

Is MD5 still useful?

MD5 is still being used today as a hash function even though it has been exploited for years.

How big is an MD5 hash?

The hash size for the MD5 algorithm is 128 bits. The ComputeHash methods of the MD5 class return the hash as an array of 16 bytes. Note that some MD5 implementations produce a 32-character, hexadecimal-formatted hash.

Do I need MD5?

Unfortunately, MD5 has been cryptographically broken and considered insecure. For this reason, it should not be used for anything. Instead, developers should switch to the Secure Hash Algorithm or a Symmetric Cryptographic Algorithm.

Why MD5 is used in PHP?

The md5() function uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm. From RFC 1321 - The MD5 Message-Digest Algorithm: "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.


2 Answers

The only acceptable basis for optimizations is data. Measure generating this inline and measure caching it.

My high-end workstation can calculate well over 100k MD5 hashes of a 10-byte data segment in a second. There would be zero benefit from caching this for me and I bet it's the same for you.

like image 121
Sander Avatar answered Oct 31 '22 21:10

Sander


Generate some sample data. Well, a lot of it. Compute the MD5 of the sample data. Measure the time it takes. Decide for yourself.

like image 36
doppelfish Avatar answered Oct 31 '22 20:10

doppelfish