Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one to use: Managed vs. NonManaged hashing algorithms

In a regular C# application which class to use for hashing: xxxManaged or xxx (i.e SHA1Managed vs SHA1) and why?

like image 918
Xaqron Avatar asked Mar 17 '11 16:03

Xaqron


3 Answers

The Non-managed hashes which end in ***Cng, ie SHA256Cng, will also have platform restrictions. They are quite a bit faster than the managed alternatives, but will fail at runtime on Windows XP, for example. If you know your program will always be run on Windows 7, Vista SP1, or 2008, however, they will generally perform quite a bit better than the managed versions, even with the native interop overhead.

If you're writing a general purpose program, the ***Managed classes will be easier to work with, as they will always work.

like image 99
Reed Copsey Avatar answered Oct 22 '22 10:10

Reed Copsey


You should use the *Managed variants; they're usually faster.

The *CryptoProvider and *CNG classes use native interop, and are usually slower.
However, I've heard that they can use hardware crypto accelerators. (I haven't checked that)

Also, the native versions are FIPS-certified; the managed versions aren't.

like image 33
SLaks Avatar answered Oct 22 '22 09:10

SLaks


The *Managed versions are written using entirely Managed code, the *Provider versions are a wrapper around the APIs. So if you always use the managed versions, your code will be portable e.g. to Mono, but if you use the Provider version you'll be limited to Windows platforms.

like image 3
PhilPursglove Avatar answered Oct 22 '22 08:10

PhilPursglove