3

I need to create an identifier for my iOS user that is unique. Unfortunately the database that it will be saved to has a set length of 30 characters and CFUUID's are 36 (32 if removing the dashes).

Is there a way to make it into a smaller string? I think CFUUID's are hex, so would it be possible to convert it to full ASCII?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Luke
  • 558
  • 1
  • 5
  • 24

2 Answers2

2

Jeff Atwood covers this in Equipping our ASCII Armor. A Base64 encoded GUID results in 22 (24 including ==) bytes. There are also other ascii formats you can use based on the post but Base64 will likely be the friendliest with the database server.

Community
  • 1
  • 1
Joe
  • 56,979
  • 9
  • 128
  • 135
  • Thanks Joe, that helped. One thing lead to another and I ended up pull the solution off of http://stackoverflow.com/questions/882277/how-to-base64-encode-on-the-iphone Worked perfect for my needs. – Luke Jun 27 '12 at 04:53
0

First, convert your hex string to NSData using something like https://stackoverflow.com/a/7318062/382374 (be sure to strip out the "-"s). Then use something like http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php to convert the NSData to base64.

Community
  • 1
  • 1
Erik
  • 7,479
  • 8
  • 62
  • 99
  • This is also a useful tool: http://tomeko.net/online_tools/hex_to_base64.php?lang=en – Erik Jul 05 '12 at 20:22