Unpredictable Unique Identifier

前端 未结 4 899
情书的邮戳
情书的邮戳 2021-01-03 03:40

For an application I am working on, I need to generate a session token which must have following properties:

  • it should be unique for the application at least,
4条回答
  •  -上瘾入骨i
    2021-01-03 04:36

    If you really and truly must have unpredictability, then generate a GUID and use a 128-bit bit mixer to rearrange the bits. Probably best to use a 64-bit bit mixer to mix the high and low portions. And, yes, there are bit mixers that guarantee unique output for every unique input.

    Note that this isn't completely unpredictable. If somebody watching knows that the value is an obfuscated GUID, then he can probably examine successive values and, with some effort, potentially reverse-engineer your bit mixer.

提交回复
热议问题