How to reduce hash value's length?

六月ゝ 毕业季﹏ 提交于 2020-01-15 05:21:09

问题


I'd like to squeeze or compress the result hash value from MD5 or SHA1 at a server side application so that at the client can decompress it or desqueeze it , is this possible ? its a usability issue for my application.


回答1:


No, hash values cannot be compressed. By design their bits are highly random and have maximum entropy, so there is no redundancy to compress.

If you want to make the hash values easier to read for users you can use different tricks, such as:

  • Displaying fewer digits. Instead of 32 digits just show 16.

  • Using a different base. For instance, if you used base 62 using all the uppercase and lowercase letters plus numbers 0-9 as digits then you could show a 128-bit hash using 22 letters+digits versus 32 hex digits:

    log62 (2128) ≈ 21.5

  • Adding whitespace or punctuation. You'll commonly see CD keys printed with dashes like AX7T4-BZ41O-JK3FF-QOZ96. It's easier for users to read this than 20 digits all jammed together.




回答2:


Hash values are quite short; attempting compression on these (quite random and highly varied) values is difficult and inefficient. If you want to save space, truncating the value could help, but keep in mind that if you do this, you increase collision space (and decrease key space).



来源:https://stackoverflow.com/questions/4116631/how-to-reduce-hash-values-length

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!