1

I am saving data hashed with keccak-256 in Solidity and I am trying read that data with PHP, but cant seem to find any good solutions.

I can get PHP to read off the data but I cant arrive at the same resulting hash to compare the results from what PHP gives to what Solidity gives in order to confirm what the data is.

Any idea how I can make this work?

1 Answer 1

4

Hashing is one-way: If you have text you can create a hash, but if you have a hash you can't use it to recreate the text.

5
  • 1
    Or put another way, you cannot turn a burger into a cow. Commented Aug 6, 2017 at 4:07
  • An alternative is encryption, which is reversible operation.
    – Ismael
    Commented Aug 6, 2017 at 9:03
  • I understand that.. I have worded it poorly. You cant undo it but you can verify the data is the same by hashing the same string on the PHP side. Example: in solidity take the word 'apple' convert it to hex '6170706c65' hash using keccak256('6170706c65'') resulting in 0x85dca312121b082f39dd34192d69dffd93c0add33dac13f7846f2975fba845c6 PHP knows what the result of apple should be using the same procedure it knows that 'apple' should become .0x85dca312121b082f39dd34192d69dffd93c0add33dac13f7846f2975fba845c6' it only needs to compare the 2 results That is what I am trying to do Commented Aug 6, 2017 at 14:49
  • You might use a library like Ethereum-PHP which is documented. Commented Mar 21, 2018 at 0:24
  • @RobHitchens You can turn a burger into a cow. If the burger has the cow dna you can clone it. And voila, you now have a cow.
    – YulePale
    Commented Jun 20, 2021 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.