如何在Ruby中解密MD5?
可能的重复:
是否可以解密 md5 哈希值?
我在 Ruby 中执行此操作:
Digest::MD5.hexdigest("Jose")
并得到“70483b6e100c9cebbffcdc62dea07eda”
但是,如何将其解密回“Jose”?
Possible Duplicate:
Is it possible to decrypt md5 hashes?
I do this in Ruby:
Digest::MD5.hexdigest("Jose")
and get "70483b6e100c9cebbffcdc62dea07eda"
But, how do I decrypt it back to "Jose"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MD5 是一种散列算法,您无法轻松地将输出解密回原始(这正是我们使用散列算法的原因)。
一个常见的例子是密码。您无需将密码存储在数据库中,而是生成原始密码的 MD5 哈希值并存储它。如果有一天有人窃取了您的数据库,他们就很难找出真正的密码,因为它们无法直接解密。
但是,当您尝试登录用户时,他将输入真实密码,然后您将再次运行 MD5 算法,并将哈希值与您存储的哈希值进行比较,如果它们相同,则用户可能输入了正确的密码。
MD5 is a hashing algorithm, you can not easily decrypt the output back to the original (and this is exactly why we use hashing algorithms).
A common example is passwords. Instead of storing a password in your database, you generate a MD5 hash of the original password and store it. If one day someone steals your database it's harder for them to figure out the real passwords, as they can not be directly decrypted.
But when you're trying to login a user, he's going to type the real password, you will then run the MD5 algorithm again and compare the hash with the one you have stored, if they're the same then the user possibly typed the correct password.
您无法“解密”它,因为它从未加密。陷门散列算法可以将多个不同的字符串映射到相同的密钥(“冲突”)。 MD5就是这样一种算法。
考虑一个更简单的哈希算法:
与 MD5 不同,该算法会产生大量哈希冲突;但是,您仍然无法将 6 '解码' 为“hello world”。您能做的最好的事情就是对自己的字符串进行哈希处理,直到找到一个产生相同结果的字符串(并希望这就是原始字符串)。
…然而,大型数据库已经
加密散列大量字符串并将它们与MD5散列相关联。例如,如果您在 http://www.md5decrypter.co.uk/ 中键入70483b6e100c9cebbffcdc62dea07eda
,你确实找回了“Jose”。如果您想在 Ruby 中执行此操作,您将执行如下操作:
You can't 'decrypt' it, as it was never encrypted. Trapdoor hashing algorithms may map multiple distinct strings to the same key (a 'collision'). MD5 is such an algorithm.
Consider a much simpler hashing algorithm:
This algorithm produces a very large number of hash collisions, unlike MD5; but still, you can't 'decode' 6 to "hello world". The best you can do is to hash your own strings until you find one that produces the same result (and hope that this is what the original was).
…That said, however, large databases exist that have already
encryptedhashed huge amounts of strings and associated them with their MD5 hash. For example, if you type70483b6e100c9cebbffcdc62dea07eda
into http://www.md5decrypter.co.uk/, you do get "Jose" back.If you wanted to do this in Ruby, what you would do is something like the following:
MD5是一种单向哈希加密算法。无法直接解密 MD5 哈希值。该算法本身使用模块化算术来打包序列化字符串,并且无法从中返回。想想看,如果你有 6 % 4 = 2,然后你有 9 % 7 = 2,那么两个结果最终都是 2。这有点像 md5 的工作原理。
获得某种形式的解密 md5 摘要的唯一方法是将其他哈希值与它进行比较。 md5("me") == hash 也是如此,然后哈希解密 = "me"。这种形式的查找使用彩虹表。您可能会幸运地在网上查找“md5 彩虹表查找”。
以下是 md5 查找网站示例:
http://www.md5decrypter.co.uk/
MD5 is a one-way hash encryption algorithm. There is no way to directly decrypt a MD5 hash. The algorithm itself uses modular arithmetic to package the serialized string and there is no way to go backwards from that. Think about it, if you have 6 % 4 = 2 and then you have 9 % 7 = 2 then both results end up as 2. This is kinda how md5 works.
The only way to get some form of un-encrypting a md5 digest is to compare other hashes to it. So does md5("me") == hash, then hash decrypted = "me". This form of a lookup uses a rainbow table. You may have some luck looking online for a "md5 rainbow table lookup".
Here is an example md5 lookup website:
http://www.md5decrypter.co.uk/