URL safe UUIDs in the smallest number of characters

后端 未结 2 1493
鱼传尺愫
鱼传尺愫 2021-02-13 00:15

Ideally I would want something like example.com/resources/äFg4вNгё5, minimum number of visible characters, never mind that they have to be percent

2条回答
  •  鱼传尺愫
    2021-02-13 00:59

    Base-64 is good for this.

    {098ef7bc-a96c-43a9-927a-912fc7471ba2}
    

    could be encoded as

    vPeOCWypqUOSepEvx0cbog
    

    The usual equal-signs at the end could be dropped, as they always make the string-length a multiple of 4. And instead of + and /, you could use some safe characters. You can pick two from: - . _ ~

    More information:

    • RFC 4648
    • Storing UUID as base64 String (Java)
    • guid to base64, for URL (C#)
    • Short GUID (C#)

提交回复
热议问题