I am working on a project in solidity where i am encode a string to SHA256 hash value, and now i want to decode SHA256 hash value and retrieve the actual data. please help hoe to do it.

Below is the code i using to hash a string.

pragma solidity ^0.4.26;

contract TestShaAlgo {
  function getSha256(string str) public view returns (bytes32) {
  bytes32 hash = sha256(abi.encodePacked(str));
  return hash;
  • 2
    The whole point about hashing functions is that they are 'one way'. A hash function is therefore not considered as an encryption function, because it is supposed to be very hard to decrypt its output back to the original input (otherwise, the hash function is weak and shouldn't be used). They are therefore designated for verification (as in authentication). – goodvibration May 14 at 7:25
  • Yes i heard these are on way, but we have online coverts where we can retrieve the original data form the hash value. Is there any way i can do that in solidity. – karthik yadav May 14 at 7:27
  • 1
    Not in solidity nor in any other language. You cannot unscramble an egg. – goodvibration May 14 at 7:28
  • But you can see in the below website that it decodes the sha256 hash value. md5decrypt.net/en/Sha256 – karthik yadav May 14 at 7:31
  • Like I said, rather than encryption/decryption, hash functions are used in order to implement the signature/verification scheme in order to authenticate an identity. For example, you create an account with a password. Instead of storing your password on my server in plaintext (leaving it exposed to hackers), I hash it and store the hash (which cannot be decrypted back to the original password). Whenever you login, you enter the password on your client side, the client side hashes it and sends the hash to the server, which can then authenticate your identity. – goodvibration May 14 at 7:36

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.