如何在 PHP 中解密 md5 字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35137474/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:22:05  来源:igfitidea点击:

How to decrypt an md5 string in PHP

phpencryptionmd5utf8-decode

提问by deepak

I have encoded a string with md5()and I want to decrypt the same string.

我已经编码了一个字符串,md5()我想解密同一个字符串。

I have written the following code:

我编写了以下代码:

<?php 

$rr = md5(utf8_encode('hello'));
echo $rr;

$rr1 = md5(utf8_decode('5d41402abc4b2a76b9719d911017c592'));
echo '<br/>' .$rr1;
?>

Now I am able to encrypt the string. But now, I want to decrypt the string. I have tried:

现在我可以加密字符串了。但是现在,我想解密字符串。我试过了:

md5(utf_decode('string'));

But it is not working. How can I decrypt the string which is encrypted with md5()?

但它不起作用。如何解密用 加密的字符串md5()

回答by Will

You can't! MD5 is a one-way hash, not encryption. The whole point is that it's supposed to be impossible to reverse. What you'd use it for is, for example, storing a password. You don't need to know what the password is; you just need to md5()whatever the user typed into the password field, and see if it matches the stored md5()value of the user's password.

你不能!MD5 是一种单向散列,而不是加密。重点是它应该是不可能逆转的。例如,您将使用它来存储密码。你不需要知道密码是什么;您只需要md5()输入用户在密码字段中输入的任何内容,并查看它是否与md5()用户密码的存储值匹配。

If you want to be able to encrypt and decrypt, look into something like AES/ Twofish / Blowfish. The MCrypt modulewill help you quite a bit.

如果您希望能够加密和解密,请查看AES/ Twofish / Blowfish 之类的东西。在这个Mcrypt模块会帮你不少。

This questionprovides some additional resources for how to encrypt and decrypt in PHP.

这个问题提供了一些关于如何在 PHP 中加密和解密的额外资源。

I should also point out that md5()is a weak, collision-prone hashing algorithm, and shouldn't be trusted for high-security applications. I would use sha256 at minimum, or sha512.

我还应该指出,这md5()是一种弱的、容易发生冲突的散列算法,不应该被高安全性应用程序信任。我至少会使用 sha256 或 sha512。