Obfuscating an ID

前端 未结 11 526
逝去的感伤
逝去的感伤 2020-11-28 02:20

I\'m looking for a way to encrypt/obfuscate an integer ID into another integer. More precisely, I need a function int F(int x), so that

  • x<->F(x
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 03:01

    I wrote an article on secure permutations with block ciphers, which ought to fulfil your requirements as stated.

    I'd suggest, though, that if you want hard to guess identifiers, you should just use them in the first place: generate UUIDs, and use those as the primary key for your records in the first place - there's no need to be able to convert to and from a 'real' ID.

提交回复
热议问题