Which one to use: Managed vs. NonManaged hashing algorithms

后端 未结 6 1783
离开以前
离开以前 2021-01-01 14:03

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

6条回答
  •  执笔经年
    2021-01-01 14:27

    Managed classes are generally "safer" to use in .NET; they implement Framework-defined interfaces like IDisposable and ICryptoServiceProvider. However, they're a bit slower because of the managed component. You should use a managed class if you need to create and destroy these helpers at will, and/or if you need to implement interface-based design patterns.

    Unmanaged classes are generally faster (because they are pre-compiled to machine code), but can be difficult to work with. Destroying an instance of an unmanaged class can be problematic and sometimes impossible. You should use these if there isn't a managed wrapper that will do the same thing (as you'll likely end up implementing your own wrapper for the unmanaged class to handle instantiation, interop and destruction), or if the usage is a one-off.

提交回复
热议问题