删除“-"有多安全?在随机生成的 UUID 中? [英] How safe is it to remove the "-" in a randomly generated UUID?

查看:35
本文介绍了删除“-"有多安全?在随机生成的 UUID 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

String uuid = UUID.randomUUID().toString().replace("-", "");

删除生成的 UUID 中的-"有多安全?删除它是否会破坏其全局唯一的目的,并使生成的 UUID 容易发生冲突?

How safe is it to remove the "-" in the generated UUID? Would removing it defeat the purpose of it being globally unique and make the generated UUID prone to collisions?

推荐答案

如果删除生成的 UUID 中的-"有多安全

how safe if is to remove the "-" in the generated UUID

它是 100% 安全的,因为破折号不是值的一部分.字符串 UUID 是 128 位值的十六进制表示.破折号仅用于显示目的,因此 UUID 会更容易显示.

It's 100% safe since the dashes aren't part of the value. The String UUID is a hex representation of a 128 bit value. The dashes are there just for display purposes so UUIDs will be a bit easier on the eyes.

在将 String 形式的 UUID 传递给外部系统(例如外部 API、数据库和类似性质的东西)时,请务必小心.他们可能希望破折号出现.

Just be careful when passing UUIDs in String form to external systems such as external APIs, databases, and things of that nature. They might be expecting the dashes to be there.

这篇关于删除“-"有多安全?在随机生成的 UUID 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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