NSData to Java String

后端 未结 2 1774
野趣味
野趣味 2021-01-16 14:59

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 no

相关标签:
2条回答
  • 2021-01-16 15:21

    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>
    
    0 讨论(0)
  • 2021-01-16 15:44

    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.

    0 讨论(0)
提交回复
热议问题