最少字符数的URL安全UUID [英] URL safe UUIDs in the smallest number of characters

查看:196
本文介绍了最少字符数的URL安全UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我想要类似example.com/resources/äFg4вNгё5这样的字符,最少数量的可见个字符,不要介意在通过HTTP传输它们之前必须对它们进行百分比编码.

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 encoded before transmitting them over HTTP.

您能说出一种方案,该方案将128b个UUID有效地编码为最少数量的可见字符,而结果中没有破坏URL的字符吗?

Can you tell a scheme which encodes 128b UUIDs into the least number of visible characters efficiently, without the results having characters which break URLs?

推荐答案

Base-64对此很有帮助.

Base-64 is good for this.

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

可以被编码为

vPeOCWypqUOSepEvx0cbog

可以删除结尾处通常的等号,因为它们总是使字符串长度为4的倍数.您可以使用一些安全字符来代替+/.您可以从以下两个选项中进行选择:- . _ ~

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: - . _ ~

更多信息:

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

这篇关于最少字符数的URL安全UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆