开发者

Algorithm for creating anonymous unique identifier from serial number

开发者 https://www.devze.com 2023-04-05 23:10 出处:网络
I would like to log some simple usage statistics for a mobile application. For the privacy of my users, I would prefer not to store their actual device serial numbe开发者_开发百科r in the database if

I would like to log some simple usage statistics for a mobile application. For the privacy of my users, I would prefer not to store their actual device serial numbe开发者_开发百科r in the database if possible. Is there a simple algorithm that can hash or transform a serial number into an anonymous identifier and cannot be reversed, while still guaranteeing uniqueness?


Yes, you want to use UUID. Pretty much all languages have this. As far as I know, they cannot be reversed to get back the original "seed".


Create a HASH of the devices serial number. A hash is by definition a one way encryption. Use the SHA-256 algorithm.

Now, depending on the size of the input, hash functions may create some collisions, this would cause your unique identifier to be not-unique in some (very rare) cases. To avoid this you could append some other piece of arbitrary information to it like IP address or a time stamp.

[SHA-256 of serial number][Time Stamp][Data to store]
0

精彩评论

暂无评论...
验证码 换一张
取 消