0

I'm trying to accomplish a task but I'm not sure how to approach the problem. I want to hash some variables inside a byte32 array. For example:

["Hashley", 32, "Random string"] -> equivalent hash

In my backend I'm listening for the events of my contract. I want the contract to emit the hash built starting from the array. My backend takes that hashing string and go back to the original message.

equivalent hash -> ["Hashley", 32, "Random string"]

How to approach such a problem? Where do I start? I know I can't use keccak algorithm because it is a one way encryption algorithm. So how can I do this?

1 Answer 1

0

I see at least four alternatives, depending on your needs:

  1. Include the plaintext version along with the hash. The backend can then verify that the hash is correct by re-hashing. But I'm guessing this isn't an option for you.

  2. If your point is to hide information, use some regular encryption. So encrypt with a key, send encrypted text on-chain, emit the data, another entity (with the key) can decrypt the data off-chain.

  3. The same as earlier, but encrypt with your wallet's public key. It can then be decrypted with the wallet's private key.

  4. Only send an ID of the data. The backend can then reference the data (in some common database for example) by the ID.

1
  • Thank you very much for the accuracy of the answer
    – Allennick
    Commented Feb 28, 2023 at 10:51

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.