如何减少哈希值的长度? [英] How to reduce hash value's length?

查看:334
本文介绍了如何减少哈希值的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在服务器端应用程序中压缩或压缩来自MD5或SHA1的结果散列值,以便在客户端可以对其进行解压缩或解压缩,这可能吗?这是我的应用程序的可用性问题.

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.

推荐答案

否,不能压缩哈希值.通过设计,它们的位是高度随机的,并且具有最大的熵,因此没有冗余可压缩.

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:

  • 显示的数字更少.而不是32位,只显示16.

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

使用其他基数.例如,如果您使用以62为基数的所有大写和小写字母以及数字0-9作为数字,则可以使用22个字母+数字与32个十六进制数字:

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:

log 62 (2 128 )≈ 21.5

log62 (2128) ≈ 21.5

  • 添加空格或标点符号.您通常会看到带有破折号的CD密钥,例如AX7T4-BZ41O-JK3FF-QOZ96.对于用户来说,阅读这些信息要比将20位数字全部塞在一起在一起更容易.

  • 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.

    这篇关于如何减少哈希值的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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