如何使ios UDID更短但仍然唯一 [英] How can I make ios UDID shorter but still unique enlough
问题描述
我想使iOS设备的UDID小于或等于15个字符.
I want to make the UDID of a iOS device to less than or equal to 15 characters.
我正在将基于Symbian的客户端-服务器软件移植到iOS.服务器端使用IMEI(15位数字)来标识客户端电话.现在在iOS上,UDID太长(40个十六进制数字).由于要最大程度地减少服务器程序或数据库的更改,因此需要将UDID存储在varchar(15)中.
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).
因此,有任何方法可以使UDID较短,但仍然具有唯一性.如果我还可以从缩短的字符串中获取UDID,那就更好了.
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.
推荐答案
您可以将十六进制数字转换为20个Latin-1字符(≤0xff)或10个Unicode
You could convert the hex digits into 20 Latin-1 characters (≤0xff) or 10 Unicode BMP characters (≤0xffff).
如果varchar(15)可以接受Unicode BMP字符,那么我们就完成了.
If that varchar(15) can accept Unicode BMP characters, then we are done.
否则,您可以从那20个Latin-1字符中砍掉最后5个字符.UDID实际上是某些设备唯一值的 SHA-1哈希,该值可以被认为是相当随机的,并且数字是均匀分布的.因此,使用15个Latin-1字符,减少的UDID应该能够表示256 15 〜10 36 设备,这远远不够.
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.
实际上,即使您仅从UDID中获取15个十六进制字符,它也已经可以表示约10 18 个设备.
In fact, even if you just take 15 hex characters from the UDID it could already represent ~ 1018 devices.
请注意,后两种方法是有损的,即无法从15个字符中获取完整的UDID.
Note that the last 2 methods are lossy, i.e. there is no way you could get the complete UDID from the 15 characters.
这篇关于如何使ios UDID更短但仍然唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!