php 如何在php中解密sha1?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30213607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to decrypt sha1 in php?
提问by Mani Kandan
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.
下面我使用 sha1 加密了一个字符串变量。现在我希望使用 sha1 函数解密数据,但我要去某个地方。请有人挺身而出并以适当的方式指导我。
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
回答by Zgr3doo
SHA-1 is an one-way hash function.
SHA-1 是一种单向哈希函数。
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
http://en.wikipedia.org/wiki/Cryptographic_hash_function
Thus you simply can not decrypt it.
因此,您根本无法解密它。
回答by Muhammad Waqar Irshad
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
简单地,您可以使用自定义编码解码作为您的密码,否则您可以使用 base64_encode() 存储在 db 和 base64_decode() 中用于配置文件等
回答by DocRattie
SHA-1 can't be decrypted directly. This is the idea behind it: encryption that can't be decrypted easily.
SHA-1 不能直接解密。这就是它背后的想法:无法轻易解密的加密。
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.
如果您想将 SHA-1 用于诸如登录之类的事情:也将输入的密码编码为 SHA-1,并检查它是否与保存在 SHA-1 中的密码相同。
回答by Badr Fennane
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.
SHA1 不能轻易解密。
通过它的唯一方法是使用蛮力破解器。
它们在网上广泛可用,例如:http: //md5-sha.com/md5-encrypt-hash-generator-online
这些网站有一个很大的数据库,其中包含已经散列的密码,这非常有用。
希望它有帮助,祝你有美好的一天。
回答by Girish Patidar
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 哈希无法解密,但您可以在许多不同的网站上在线尝试,这些网站具有密码数据库,它是 SHA1 哈希。因此,您可以尝试以下在线工具:
回答by Aditya P Bhatt
You cannot decrypt it.
你不能解密它。
Hashing is one way only - MD5 and SHA-1 both are one-way hash functions.
散列只是一种方式——MD5 和 SHA-1 都是单向散列函数。
You have to create new hash of the input at the login form and check if it is equal to the stored hash.
您必须在登录表单中创建输入的新散列并检查它是否等于存储的散列。
回答by imtaher
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,
然后创建两列,一列用于encrypted_password,一列用于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.
通过这种方式,您可以对列 encrypted_password 使用登录名,并在仪表板中为用户使用列 not_encrypted_password 显示密码。