Create hash in c# and validate in solidity

by fancycat   Last Updated January 14, 2018 00:28 AM

I'm trying to build an app that will call a contract from javascript. I want the contract to validate that the parameters weren't tampered with. In order to do that, my plan was to figure out the parameters server-side, hash the combination of parameters, and sign the hash. I'd pass the hash and signature along to the contract for the contract to validate. The hash would prove the parameters haven't changed and the signature would prove that I generated the hash.

I'm currently trying to figure out the hashing part.

void Main()
    var bytes = ASCIIEncoding.ASCII.GetBytes("abc");

    SHA256 hasher = SHA256Cng.Create();
    var hashed = hasher.ComputeHash(bytes);
    Console.WriteLine(BitConverter.ToString(hashed).Replace("-", string.Empty));

gives me an output of BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD

On the other side of the fence I have

pragma solidity 0.4.18;    

contract HashCheck {    
    function hash(bytes32 toHash) public returns(bytes32) {
        bytes32 hashed = sha256(toHash);
        return hashed;        

which returns


I'm happy to try out keccak (sha3) hashing but I haven't figured out how to do that in C# yet.

Related Questions

Which cryptographic hash function does Ethereum use?

Updated September 27, 2017 21:28 PM

What is a block hash?

Updated December 13, 2017 04:28 AM

Difference between keccak256 and sha3

Updated November 10, 2017 08:28 AM