将 SHA1 转换回字符串 [英] Convert SHA1 back to string

查看:84
本文介绍了将 SHA1 转换回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序上有一个用户模型,我的密码字段使用 sha1.我想要的是,当我从数据库中获取 sha1 时,再次使其成为字符串.我该怎么做?

解决方案

你不能 - SHA1 是一种单向哈希.鉴于 SHA1(X) 的输出,无法检索 X(至少,在没有蛮力搜索或 字典/彩虹表扫描)

考虑这个问题的一个非常简单的方法是想象我给你一组三位数相加,然后你告诉我那个和的最后两位数.我不可能从这两位数字中确切地计算出您从哪个数字开始.

另见

思想与 MD5 相关,这些其他问题也可能对您有所启发:

I have a user model on my app, and my password field uses sha1. What i want is to, when i get the sha1 from the DB, to make it a string again. How do i do that?

解决方案

You can't - SHA1 is a one-way hash. Given the output of SHA1(X), is not possible to retrieve X (at least, not without a brute force search or dictionary/rainbow table scan)

A very simple way of thinking about this is to imagine I give you a set of three-digit numbers to add up, and you tell me the final two digits of that sum. It's not possible from those two digits for me to work out exactly which numbers you started out with.

See also

Thought relating MD5, these other questions may also enlighten you:

这篇关于将 SHA1 转换回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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