Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SHA1 back to string

I have a user model on my app, and my password field uses sha1. What i want is to, when i get the sha1 from the DB, to make it a string again. How do i do that?

like image 925
Onizudo Avatar asked Dec 08 '22 01:12

Onizudo


1 Answers

You can't - SHA1 is a one-way hash. Given the output of SHA1(X), is not possible to retrieve X (at least, not without a brute force search or dictionary/rainbow table scan)

A very simple way of thinking about this is to imagine I give you a set of three-digit numbers to add up, and you tell me the final two digits of that sum. It's not possible from those two digits for me to work out exactly which numbers you started out with.

See also

  • Is it possible to reverse a sha1?
  • Decode sha1 string to normal string

Thought relating MD5, these other questions may also enlighten you:

  • Reversing an MD5 Hash
  • How can it be impossible to “decrypt” an MD5 hash?
like image 172
Paul Dixon Avatar answered Dec 25 '22 20:12

Paul Dixon