views:

187

answers:

2

Hello :)

The question is pretty much self-explanatory. I Googled many sites, many methods, tried many encodings, but I can't get it to match.

I'm trying to make the string "asdasd" match. (http://www.fileformat.info/tool/hash.htm?text=asdasd)

+2  A: 

Try this

using System.Security.Cryptography

public static string HashPassword(string unhashedPassword)
{
    return BitConverter.ToString(new SHA512CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(unhashedPassword))).Replace("-", String.Empty).ToUpper();
}
The Matt
Easy, nice, small, fast lets say perfect!
Polo
A: 

BitConverter works just fine ...

var testVal = "asdasd";
var enc = new ASCIIEncoding();
var bytes = enc.GetBytes( testVal );

var sha = new SHA512Managed();
var result = sha.ComputeHash( bytes );

var resStr = BitConverter.ToString( result );
var nodash = resStr.Replace( "-", "" );

nodash.Dump();

(Fixed for 512-bit hash, sorry :)

JP Alioto
I don't know if that's just a typo in your code, but he was asking for sha512, not sha256.
André Hoffmann