散列结果是否与源值相同? [英] Is a hash result ever the same as the source value?

查看:172
本文介绍了散列结果是否与源值相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更像是加密理论的问题,但是哈希算法的结果有可能与源的值相同吗?例如,假设我有一个字符串:

This is more of a cryptography theory question, but is it possible that the result of a hash algorithm will ever be the same value as the source? For example, say I have a string:

baf34551fecb48acc3da868eb85e1b6dac9de356

如果我得到SHA1哈希,结果是:

If I get the SHA1 hash on it, the result is:

4d2f72adbafddfe49a726990a1bcb8d34d3da162

理论上,是否有这两个值匹配的情况?我不是在这里询问SHA1 - 这只是我的例子。我只是想知道如果哈希算法是建立在这样的方式,以防止这种情况。

In theory, is there ever a case where these two values would match? I'm not asking about SHA1 specifically here - it's just my example. I'm just wondering if hashing algorithms are built in such a way as to prevent this.

推荐答案

散列算法 - 但我会惊讶地看到任何明确阻止这一点。毕竟,它真的不重要。

Well, it would depend on the hashing algorithm - but I'd be surprised to see anything explicitly prevent this. After all, it really shouldn't matter.

我怀疑这是不太可能发生,当然(对于加密散列)...但即使它,应该不会导致问题。

I suspect it's very unlikely to happen, of course (for cryptographic hashes)... but even if it does, that shouldn't cause a problem.

对于非加密散列(用于哈希表等),在某些情况下返回源值是完全合理的。例如,在Java中, Integer.hashCode()只返回嵌入的值。

For non-crypto hashes (used in hash tables etc) it would be perfectly reasonable to return the source value in some cases. For example, in Java, Integer.hashCode() just returns the embedded value.

这篇关于散列结果是否与源值相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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