9

Below i had encrypted a string varible using sha1. And now i would wish to decrypt data using sha1 function, but am going some where. Would some one come forward and guide me in proper way please.

Below is my code

<?php
 $variable = "tiger";
 echo $variable;
 $encrypt = sha1($variable);
 echo $encrypt;
 $decrypt = sha1($encrypt);
 echo $decrypt;
 ?>

And i get output like this

tiger
46e3d772a1888eadff26c7ada47fd7502d796e07
989df2c8b5ea37eb7cfde0527d94c01a15257002
asked May 13, 2015 at 11:34
6
  • 3
    I think you misunderstood something - sha1 is not an encryption in the way that it can be (easily) decrypted (see this answer) Commented May 13, 2015 at 11:36
  • 7
    It's not possible to decrypt sha1. With sha1 you can hash a string, once a string is hashed you cannot decrypt it. Commented May 13, 2015 at 11:36
  • Perhaps you're thinking that sha1() is a simple Caesar cypher like str_rot13(): $variable = "tiger"; echo $variable; $encrypt = str_rot13($variable); echo $encrypt; $decrypt = str_rot13($encrypt); echo $decrypt; Commented May 13, 2015 at 11:40
  • What are you using this for? You can not decrypt! These are one way hashing algorithms made to be irreversible however it is possible to use a "Rainbow table" to figure out what the original content was. Commented May 13, 2015 at 11:40
  • You can not decrypt sha1() bcoz sha1 is not an encryption process. Its make data hash. So you can not retrieve it in original form Commented May 13, 2015 at 11:40

8 Answers 8

30

SHA-1 is an one-way hash function.

According to wikipedia

A cryptographic hash function is a hash function which is considered practically impossible to invert, that is, to recreate the input data from its hash value alone.

http://en.wikipedia.org/wiki/Cryptographic_hash_function

Thus you simply can not decrypt it.

answered May 13, 2015 at 11:42
Sign up to request clarification or add additional context in comments.

3 Comments

But you can do it
What I mean is you can do it with brute force. But it would take some much time and resources to accomplish that.
Only brute-force method which I know is not using your hashed value as an input. It instead tries to produce same result as your hash by using wide input set and compares output of every computation with your hash. So there is no decoding involved in this process.
1

SHA-1 can't be decrypted directly. This is the idea behind it: encryption that can't be decrypted easily.

The only way to solve it is brute-force: Try to guess the correct result by encoding phrases and checking if they fit the provided phrase.

If you want to use SHA-1 for stuff like logins: Encode the entered password in SHA-1 as well and check if it's the same as one saved in SHA-1.

YakovL
8,45813 gold badges74 silver badges117 bronze badges
answered May 13, 2015 at 12:08

Comments

1

simply you can use custom encoding decoding for your password if not then you can use base64_encode() to store in db and base64_decode() for using in profile etc

answered Feb 14, 2019 at 6:58

Comments

0


SHA1 cannot be derypted easily.
The only way through it is a brute-force cracker.
They're widely available online like: http://md5-sha.com/md5-encrypt-hash-generator-online
Those websites have a large database of already hashed passwords which can be very useful.
Hope it helps, have a nice day.

answered Feb 1, 2016 at 15:28

Comments

0

SHA1 hash can't be derypted but you can try online on many different sites which have hug database of password and it's SHA1 hash. So you can try below online tools :

SHA1 Decoder Online

SHA1 tool

answered May 21, 2016 at 7:12

Comments

0

You cannot decrypt it.

Hashing is one way only - MD5 and SHA-1 both are one-way hash functions.

You have to create new hash of the input at the login form and check if it is equal to the stored hash.

answered Jan 15, 2017 at 9:36

Comments

0

In short sha1() CAN be decrypted. However only fairly simple strings can be. A password with numbers, upper and lower case and special characters will prove difficult but the likes of Password12345 can be decrypted via -

https://md5hashing.net/hash/sha1

***Bit more research. sha1() does not ever change how it encrypts the characters - so for example "MyPassword that was encrypted with sha1() 6 years ago STILL gives the output of "daa1f31819ed4928fd00e986e6bda6dab6b177dc" today in 2020.

These values are obviously stored in the above website and as time goes on the library of recognised passwords grows.

Comments

-1

If you can't decrypt and you want to show the value then use this method.

Example you are creating login form with password encrypted and want to show password to user after login in their dashboard.

then create two columns one column is for encrypted_password and one for not_encrypted_password,

$not_encrypted_password="password";
$encrypted_password =sha1("password");
$sql = mysqli_query($conn,"INSERT INTO user (not_encrypted_password,encrypted_password)VALUES('$not_encrypted_password','$encrypted_password')");

in this way you can use login for column encrypted_password and to show password in dashboard for user use column not_encrypted_password.

answered Mar 24, 2018 at 9:00

1 Comment

never store unencrypted passwords in databases.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.