如何解密PHP中的md5字符串 [英] How to decrypt an md5 string in PHP

查看:291
本文介绍了如何解密PHP中的md5字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我写了以下代码:

<?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'));

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

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

推荐答案

你不能! MD5是单向散列,不加密。总之,应该是不可能扭转的。你使用它是例如存储密码。你不需要知道密码是什么;您只需要输入密码字段中的 md5(),并查看它是否与存储的 md5()用户密码的值。

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.

如果您想要加密和解密,请查看 AES / Twofish / Blowfish。 MCrypt模块将有助于您。

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

这个问题为PHP中加密和解密提供了一些额外的资源。

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

我还应该指出, md5()是一个弱的,容易出错的哈希算法,不应该被高安全性应用信任。我最少使用sha256,或sha512。

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.

这篇关于如何解密PHP中的md5字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆