python中crypto哈希和哈希表哈希之间有什么区别?

时间:2015-12-14 15:16:29

标签: python python-2.7 hash cryptography

什么是加密哈希以及什么算法?它与python中的普通哈希有什么不同?如何确定使用哪个?

EX: 加密哈希函数
你好 - aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
helld - 44d634fa6b81353bc3ed424879ffd013501ade53

哈希函数
哈希("你好")-1267296259
hash(" helld")-1267296266

请帮帮我

1 个答案:

答案 0 :(得分:4)

Cryptographic Hash functions are different from Hashtable Hash functions. One main difference is that cryptographic hash functions are designed not to have hash collision weaknesses. They are designed to be more secure and irreversible in most cases. But Hashtable hash functions like hash are faster and are designed to use to quickly access items in memory or comparing items or etc.

Suppose two differenct Scenarios. If you want to store passwords in a database you must use something like pbkdf2 so it is more secure and so slower to generate in order to prevent brute forces. But in another case you just want to have a set of items and check if an item exists in that set. You can simply store a 32-bit or 64-bit hash of items(e.g. classes) and compare hashes quickly instead of classes.

For example for string "hello", it is much faster to compute and store 1267296259 as it is a 32-bit integer and more secure and slower to compute and store aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d.

P.S. A good example is here.