How to get a one-way hash for a given string in .NET?

Is there a built-in library in .NET that can calculate a secure one-way hash? I mean a library that implements the SHA-2 cryptographic hash function or something like that.

If there is no SHA-2 implementation, then a hash function will be rather weak. If there are more options, I prefer the most secure.

Please indicate a usage example, for example. provide code that returns a one-way hash for the string mySampleString .


EDIT: Please provide an example and the hash algorithm used.

+4
source share
3 answers

You can use the SHA256Mananged class to generate a hash of the string. The ComputeHash documentation provides a complete example.

If you focus only on Vista +, you can use the faster SHA256Cng instead . Just understand that it will throw XP.

+4
source

Look in the System.Security.Cryptography namespace.
There you have a bunch of SHA algorithms, MD5, etc.

+2
source

Source: https://habr.com/ru/post/1343225/


All Articles