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

后端 未结 5 1361
借酒劲吻你
借酒劲吻你 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:28

    It's a generalization of the birthday problem. In you case n is number of documents, and instead of constant 365 you'd have number of possibilities the cutoff gives you (so for k bits it's 2k).

    Of course exact calculation is out of the question, but you might use approximation.

提交回复
热议问题