1

I've been writing a Web Application recently that interacts with iPhones. The iPhone iphone will actually send information to the server in the form of a plist. So it's not uncommon to see something like...

<key>RandomData</key>
<data>UW31vrxbUTl07PaDRDEln3EWTLojFFmsm7YuRAscirI=</data>

Now I know this data is hashed/encrypted in some fashion. When I open up the plist with an editor (Property List Editor), it shows me a more "human readable" format. For example, the data above would be converted into something like...

<346df5da 3c5b5259 74ecf683 4431249f 711630ba 232c54ac 9bf2ee44 0r1c8ab2>

Any idea what the method of converting it is? Mainly I'm looking to get this into a Java String.

Thanks!

Staros
  • 3,232
  • 6
  • 30
  • 41

2 Answers2

4

According to our friends at wikipedia, the <data> tag contains Base64 encoded data. So, use your favorite Java "Base64" class to decode (see also this question).

ps. technically, this is neither "hashed" nor "encrypted", simply "encoded". "Hashed" implies a one-way transformation where multiple input values can yield the same output value. "Encrypted" implies the need for a (usually secret) "key" to reverse the encryption. Base64 encoding is simply a way of representing arbitrary binary data using only printable characters.

Community
  • 1
  • 1
David Gelhar
  • 27,873
  • 3
  • 67
  • 84
2

After base64 decoding it you need to hex encode it. This is what PL Editor is showing you.

So...

<key>SomeData</key>
<data>UW31ejxbelle7PaeRAEen3EWMLojbFmsm7LuRAscirI=</data?

Can be represented with...

byte[] bytes = Base64.decode("UW31ejxbelle7PaeRAEen3EWMLojbFmsm7LuRAscirI=");
BigInteger bigInt = new BigInteger(bytes);
String hexString = bigInt.toString(16);
System.out.println(hexString);

To get...

<516df5aa 3c5b5259 74ecf683 4401259f 711630ba 236c59ac 9bb2ee44 0b1c8ab2>
Staros
  • 3,232
  • 6
  • 30
  • 41
  • My hex converter isn't the best, but the idea is the same. – Staros Sep 27 '10 at 04:23
  • This code cuts off any leading zeros... Any idea on how to prevent this? – Bashorings Jun 18 '12 at 08:12
  • @Bashorings: Manually print each digit in the `bytes` array by looping through them or use an API that does this for you like `javax.xml.bind.DatatypeConverter.printHexBinary` – rpetrich Sep 30 '13 at 07:37