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?

3

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.

| improve this answer | |
  • 1
    Or put another way, you cannot turn a burger into a cow. – Rob Hitchens Aug 6 '17 at 4:07
  • An alternative is encryption, which is reversible operation. – Ismael Aug 6 '17 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 – Dino Anastos Aug 6 '17 at 14:49
  • You might use a library like Ethereum-PHP which is documented. – digitaldonkey Mar 21 '18 at 0:24

Your Answer

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

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