Manikandan
Manikandan

Reputation: 699

How to decrypt sha1 in php?

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

Upvotes: 9

Views: 102936

Answers (8)

Sam Donaghy-Bell
Sam Donaghy-Bell

Reputation: 35

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.

Upvotes: 0

Muhammad Waqar Irshad
Muhammad Waqar Irshad

Reputation: 11

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

Upvotes: 1

imtaher
imtaher

Reputation: 438

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.

Upvotes: -1

DocRattie
DocRattie

Reputation: 1423

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.

Upvotes: 1

Aditya P Bhatt
Aditya P Bhatt

Reputation: 22071

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.

Upvotes: 0

Girish Patidar
Girish Patidar

Reputation: 364

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

Upvotes: 0

Badr Fennane
Badr Fennane

Reputation: 27


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.

Upvotes: 0

Zgr3doo
Zgr3doo

Reputation: 1855

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.

Upvotes: 30

Related Questions