My Console App is usin .Net 6.0. I want to generate a crypto wallet KeyPair that corresponds to the public address. However when I hash it with Keccak 256, Using Nethereum Sha3Keccak as shown below, the hash is different than expected. The string that I want to hash is DF4566150FEE083F2A956B8666E666CD8AB6DC6A05A0D8722EDD8E175BD83FF662B0088FE94B03C5F1FD881B7CB522AE2AE0C19CC9BB4969EC702C7016C6D887
The result should be 53DB7117947F19F22349D28908B79CB67FF2E0D7A15D2721C49AB05B5287F315.
However, the result with my code is 7739b8b83fb1f0387e7ade80c6f77745ee105032c7333213feb2c5ed5e23f395.
I used an online utility - https://emn178.github.io/online-tools/keccak_256.html to try and figure it out and when I select HEX there it generates the proper hash, but when it's TEXT it provides 7739b8b83fb1f0387e7ade80c6f77745ee105032c7333213feb2c5ed5e23f395 as well.
Any suggestions as to what I'm doing wrong? Thank you.
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Nethereum.Signer;
using Nethereum.Signer.Crypto;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Util;
namespace App1
{
class Program
{
static void Main ()
{
string str = "DF4566150FEE083F2A956B8666E666CD8AB6DC6A05A0D8722EDD8E175BD83FF662B0088FE94B03C5F1FD881B7CB522AE2AE0C19CC9BB4969EC702C7016C6D887"
Sha3Keccack shaKec = new Sha3Keccack();
byte[] ba = StringToByteArray(str);
string hex = Convert.ToHexString(ba);
string kec = shaKec.CalculateHash(hex);
Console.WriteLine(kec);
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
}
}