How much can you truncate a SHA1 hash and be reasonably sure of having an unique ID?

后端 未结 5 1391
借酒劲吻你
借酒劲吻你 2020-12-24 13:41

I am making an application that stores documents and gives each one a UID based on a SHA1 digest of a few things including the timestamp. The digest has a lot of characters,

5条回答
  •  轮回少年
    2020-12-24 14:33

    There really isn't a value for this; part of what makes SHA a good general-purpose hashing algorithm is that similar data does not necessarily produce similar hashed values. Your best bet (without knowing anything else about your system) would just be to search the list of documents whose hashes start with the value supplied by the user, then either present them with a list of documents to select from or go directly to the document if there's only one.

提交回复
热议问题