What one-way hash function to use?
Posted by Jonas Elfström Tue, 27 Feb 2007 16:01:00 GMT
Cryptographic hash function takes a message of any length as input and outputs a very large but fixed length number. That number is called a message digest, fingerprint, or sometimes a cryptographic hash. They can be used to represent passwords without having to know the actual password. Such a hash can also be used as signature that makes it possible to verify that the content of a message hasn't been tampered with.
MD5 got into problems over 10 years ago and SHA-1 could to be heading the same way. Until the new standard is published I would follow the cryptographic experts advice and use SHA-2.
Ruby
require 'digest/sha2'
quickfox="The quick brown fox jumps over the lazy dog"
Digest::SHA256.hexdigest(quickfox)
C#
using System.Security.Cryptography;
...
ASCIIEncoding byteConverter = new ASCIIEncoding();
string quickfox="The quick brown fox jumps over the lazy dog";
HashAlgorithm sha256 = new SHA256Managed();
byte[] hash = sha256.ComputeHash(byteConverter.GetBytes(quickfox));
crypt.Text = Convert.ToBase64String(hash);