0

I want to generate hash of string received through function argument. Sha256 require bytes in argument. How can I convert and then save hash in _hash variable.

struct ORGANIZATION{
    bytes32 hash;
    uint org_number;
}

function add_organization(string memory _stringvalue) public{
 bytes32 _hash;
 _hash=sha256(_stringvalue);
 organization[organization_counter].hash=_hash;
 organization[organization_counter].org_number=organization_counter;
 organization_counter++;
}
1
  • Try bytes32 _hash = keccak256(_stringvalue);. – goodvibration Jan 4 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.