Let's say I'm given a specific SHA-256 hash.

Further assume that the SHA-256 input, that yielded this hash contained a known sub-string.
Is there a way to find the input (containing the specific substring) that hashes to the given output?

If so, is it possible to further find an input of length N (containing the substring) to be hashed to the same SHA-256 hash?

  • $\begingroup$ I've re-formulated your question and removed the examples you gave. This is to prevent this question from being closed as "off-topic for analyzing a block of data". Furthermore I've slightly reformulated your second paragraph. The question by itself stayed the same. Please flag this comment as "obsolete" once you have read it. Our mods will delete it then. $\endgroup$ – SEJPM Feb 19 '16 at 20:58
  • 2
    $\begingroup$ Welcome to Cryptography Stackexchange. What you're looking for is called "finding a pre-image" and finding a "2nd-preimage". For the general case this is really hard. In your specific case however it may be possible to simply try all possibilities to find a matching hash (standard pre-image) while finding the second preimage still won't be possible. $\endgroup$ – SEJPM Feb 19 '16 at 21:02

SHA-256 is¹ a cryptographic hash function. As such, it has preimage resistance: given a hash value, there is no way to find a string with that hash, except by trying all strings until you find one that works. Therefore you'll have to try all possible inputs, i.e. all strings that contain the known substring. (You can of course be smart about it: try the most likely strings first, if there's such a thing as most likely in your scenario.)

If you do find a string, you can be confident that it's the right one. Cryptographic hash functions also have the collision resistance property: it is infeasible (i.e. practically impossible) to find distinct strings with the same hash. There is no way to find another string with the same hash, of length N or otherwise.

¹ As far as anybody knows, or at least anybody who speaks publicly on the topic.


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.