在这种情况下使用 md5 哈希值或 crc32 哪一个
我需要一个可以用少于 26 个字符表示的哈希值 md5 产生 32 个字符长字符串,如果将其转换为 base 36 多好啊,
我哈希的需要不是为了密码学,而是为了唯一性,基本上根据输入时间和输入数据来识别每个输入。目前我可以认为
$hash=md5( str_ireplace(".","",microtime()).md5($input_data) ) ;
$unique_id= base_convert($hash,16,36) ;
应该像这样或者使用 crc32 这将提供更小的哈希大小,但我担心它不会那么独特?
I need a hash that can be represented in less than 26 chars
Md5 produces 32 chars long string , if convert it to base 36 how good will it be,
I am need of hash not for cryptography but rather for uniqueness basically identifying each input dependent on time of input and input data. currently i can think of this as
$hash=md5( str_ireplace(".","",microtime()).md5($input_data) ) ;
$unique_id= base_convert($hash,16,36) ;
should go like this or use crc32 which will give smaller hash size but i afraid it wont be that unique ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为可以采取更简单的解决方案。
根据你的说法,你有26个字符的空格。然而,为了澄清我对性格的理解以及你对性格的理解,让我们进行一些挖掘。
MD5 哈希值维基百科生成 16 字节哈希值。
CRC32 算法产生 4 字节哈希值。
我将“字符”(最简单的意义上)理解为 ASCII 字符。每个 ascii 字符(例如 A = 65)都是 8 位长。
MD5算法产生16字节*每字节8位=128位,CRC32是32位。
您必须了解哈希值在数学上不是唯一的,但“可能是唯一的”。
因此,根据您的描述,我的解决方案是将散列的位表示为 ascii 字符。
如果只能在 MD5 和 CRC32 之间进行选择,那么答案就是 MD5。但您也可以安装 SHA-1 160 位哈希值 < 26 个字符的字符串(长度为 20 个 ascii 字符)。
如果您关心每个哈希使用的符号集,两个哈希都在集合 [A-Za-z0-9] 中(我相信) 。
最后,当您将本质上是数字的内容从一种基数转换为另一种基数时,数字不会改变,因此算法的强度也不会改变;它只是改变了数字的表示方式。
I think a much simpler solution could take place.
According to your statement, you have 26 characters of space. However, to clarify what I understand to be character and what you understand to be character, let's do some digging.
The MD5 hash acc. to wikipedia produces 16 byte hashes.
The CRC32 algorithm prodces 4 byte hashes.
I understand "characters" (in the most simplest sense) to be ASCII characters. Each ascii character (eg. A = 65) is 8 bits long.
The MD5 aglorithm produces has 16 bytes * 8 bits per byte = 128 bits, CRC32 is 32 bits.
You must understand that hashes are not mathematically unique, but "likely to be unique."
So my solution, given your description, would be to then represent the bits of the hash as ascii characters.
If you only have the choice between MD5 and CRC32, the answer would be MD5. But you could also fit a SHA-1 160 bit hash < 26 character string (it would be 20 ascii characters long).
If you are concerned about the set of symbols that each hash uses, both hashes are in the set [A-Za-z0-9] (I believe).
Finally, when you convert what are essentially numbers from one base to another, the number doesn't change, therefore the strength of the algorithm doesn't change; it just changes the way the number is represented.