问题描述
我需要将消息散列为30个字符的字符串.对于这种用法,最好和最安全的哈希函数是什么?
I need to hash a message into a string of 30 chars. What's the best and most secure hash function for this usage?
推荐答案
30个字符(字节)为240位.
Thirty characters (bytes) is 240 bits.
如果您不能移动球门柱以允许32个字符,那么您可能最终会使用SHA-1,该SHA-1会生成160位或20个字节.使用Base-64编码时,将为28个字符.如果您使用十六进制编码,它将是40个字符,名义上超出了范围.如果使用32个字符,则可以使用SHA-256,但是Base-64编码会将该大小增加到44个字符,而十六进制编码会将大小增加到64个字符.
If you can't move the goal-post to allow 32 characters, then you will probably end up using SHA-1, which generates 160-bits or 20 bytes. When Base-64 encoded, that will be 28 characters. If you use a hex-encoding, it will be 40 characters, which is nominally out of range. With 32 characters, you could use SHA-256, but Base-64 encoding would increase that size (to 44 characters) and hex-encoding increases the size to 64 characters.
如果必须使用十六进制编码并且可以达到32个字节,则可以使用生成128位的MD5,尽管不建议将其用于任何新系统.通过Base-64编码,MD5使用24个字符.否则,您将使用非常不安全的算法-完全不建议使用.
If you must use hex-encoding and can go to 32 bytes, then MD5 - which generates 128 bits - could be used, though it is not recommended for any new systems. With Base-64 encoding, MD5 uses 24 characters. Otherwise, you are using very minimally secure algorithms - not recommended at all.
这篇关于散列函数产生30个字符的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!