There are multiple errors in your C# code.
Compare the following and try to figure out exactly where the faults are.
public static string HashSHA512( string phrase )
{
if( m_SHA512HashProvider == null )
m_SHA512HashProvider = new SHA512CryptoServiceProvider();
byte[] hashed = m_SHA512HashProvider.ComputeHash(Encoding.UTF8.GetBytes(phrase)); // or ASCII if that's sufficient for you input data.
return BitConverter.ToString( hashed );
}
Some hints:
- Use
UTF8
instead ofASCII
(some characters might get truncated) GetBytes
doesn't return a length of something. It returns an array of bytes.ComputeHash
doesn't have anout
orref
parameter and sincem_HashBuffer
contains nothing, ifm_HashBuffer
is null, the hash is always computed on nothing.
Edit
Looking at the node.js API it seems that in C# you need to do an additional step:
return BitConverter.ToString(hashed).Replace("-", "").ToLower();
This is because the digest
method doesn't add the hyphens and all characters are lower case.
Disclaimer: Code not tested.