如何使 ios UDID 更短但仍然足够独特

发布于 2024-10-30 15:48:23 字数 244 浏览 0 评论 0原文

我想让iOS设备的UDID小于或等于15个字符。

我正在将基于 Symbian 的客户端服务器软件移植到 iOS。服务器端使用 IMEI(15 位数字)来识别客户端电话。现在在 iOS 上,UDID 太长(40 个十六进制数字)。由于我想尽量减少服务器程序或数据库的更改,因此我需要将 UDID 存储在 varchar(15) 中。

因此,有任何方法可以使 UDID 更短,但仍然足够唯一。如果我还可以从短字符串中获取 UDID,那就更好了。

I want to make the UDID of a iOS device to less than or equal to 15 characters.

I am porting a Symbian based client-server software to iOS. The server side uses IMEI (15 digits)to id a client phone. Now on iOS, UDID is too long(40 hex digits). As I want to minimize the change of server program or DB, I need to store the UDID in a varchar(15).

So it's there any way to make the UDID shorter but still unique enlough. It could be much better if I can also get the UDID from the shorted string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月蹉跎了容颜 2024-11-06 15:48:23

您可以将十六进制数字转换为 20 个 Latin-1 字符 (≤0xff) 或 10 个 Unicode BMP 字符 (≤0xffff)。

如果 varchar(15) 可以接受 Unicode BMP 字符,那么我们就完成了。

否则,您可以从这 20 个 Latin-1 字符中截取最后 5 个字符。 UDID 实际上是一些设备唯一值的 SHA-1 哈希,它可以被认为是相当随机的并且数字是均匀分布的。因此,使用 15 个 Latin-1 字符,简化后的 UDID 应能够表示 25615 ~ 1036 台设备,这已经足够了。

事实上,即使您只从 UDID 中获取 15 个十六进制字符,它也已经可以代表约 1018 台设备。

请注意,最后两种方法是有损的,即您无法从 15 个字符中获取完整的 UDID。

You could convert the hex digits into 20 Latin-1 characters (≤0xff) or 10 Unicode BMP characters (≤0xffff).

If that varchar(15) can accept Unicode BMP characters, then we are done.

Otherwise, you could chop the last 5 characters from that 20 Latin-1 characters. The UDID is in fact a SHA-1 hash of some device-unique values, which can be considered quite random and the digits are uniformly distributed. Therefore, with 15 Latin-1 characters the reduced UDID should be able to represent 25615 ~ 1036 devices, which is much more than enough.

In fact, even if you just take 15 hex characters from the UDID it could already represent ~ 1018 devices.

Note that the last 2 methods are lossy, i.e. there is no way you could get the complete UDID from the 15 characters.

独守阴晴ぅ圆缺 2024-11-06 15:48:23

我刚刚写了这个要点 -> https://gist.github.com/3996097

你对 CFUUID + sha1 + 子字符串 + 有何看法随机大写 ?

//Get a random hash (Generated from CFUUID+sha1)
NSString *hash = [NSString sha1:[NSString getUUID]];

//Shorten the sha1
NSString *short_random_id = [hash substringFromIndex:[hash length]-10];

//Random uppercase / lowercase the id
NSMutableString *random_id_final = [NSMutableString string];
for (NSUInteger i = 0; i < [short_random_id length]; i++)
{
    NSString *substring = [short_random_id substringWithRange:NSMakeRange(i, 1)];
    [random_id_final appendString:(rand() % 2) ? [substring lowercaseString] : [substring uppercaseString]];
}

I just wrote this gist -> https://gist.github.com/3996097

What do you think about a CFUUID + sha1 + substring + random uppercase ?

//Get a random hash (Generated from CFUUID+sha1)
NSString *hash = [NSString sha1:[NSString getUUID]];

//Shorten the sha1
NSString *short_random_id = [hash substringFromIndex:[hash length]-10];

//Random uppercase / lowercase the id
NSMutableString *random_id_final = [NSMutableString string];
for (NSUInteger i = 0; i < [short_random_id length]; i++)
{
    NSString *substring = [short_random_id substringWithRange:NSMakeRange(i, 1)];
    [random_id_final appendString:(rand() % 2) ? [substring lowercaseString] : [substring uppercaseString]];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文