c# - .NET SHA256 Vs Object.GetHashCode() -


What is the professional / cons when it comes to using SHA256 vs. object? GetHashCode ()?

In the code given below, output is similar for both methods, although GetHashCode () seems very simple, less objects / codes are required.

  class program {static void main (string [] args) {TestGetHashCode (); TestSha256 (); Console.Read (); } Static zero testSha256 () {Console.WriteLine ("test SHA256"); Unicode encoding byteConverter = new Unicode encoding (); SHA256 sha256 = SHA256.Create (); String data = "a paragraph of text"; Byte [] hash = sha256 Compact hash (byte connor gatbytes (data)); Data = "a paragraph of changed text"; Byte [] hashb = sha256 Compact hash (byte connor gatebacks (data)); Data = "a paragraph of text"; Byte [] hash c = sha256 Compact hash (byte connor gatebacks (data)); Console.WriteLine (hashA.SequenceEqual (hashB)); // Displays: False Console.light line (Hashee.Sewen's Aqual (hash)); // shows: true} static void TestGetHashCode () {Console.WriteLine ("test object. GetHashCode ()"); String data = "a paragraph of text"; Inti hash = Data. Gatehashcode (); Data = "a paragraph of changed text"; Int hashby = data Gatehashcode (); Data = "a paragraph of text"; Int Hash C = Data GetHashCode (); Console.WriteLine (hashA.Equals (hashB)); // shows: wrong console Wrightite (hash.excel (hash)); // shows: true}}  

You can not compare two because they What is your goal for two completely different purposes? Encryption or simple object lookup?

For object lookup (in hashtabil): GetHashCode ()

For encryption: eg with SHA256 eg AES

GetHashCode () should be overridden for its type and ideally should only use irreversible areas, i.e. Fields do not change during the lifetime of the object, the field read-only is a good example of this; -)

SHA256 is used for example to use an encryption algorithm for hash password which is 256-bit copies. The point of the hashing algorithm used for encryption is that it should be slow (as opposed to the object lookup scenario) to make the passwords of brutality attack more difficult.

There is no professional / opposition in this way, but actually use the right tools for the purpose depending on your goal: -)


Comments