NSData 到 Java 字符串

发布于 2024-09-24 21:14:05 字数 488 浏览 0 评论 0原文

我最近一直在编写一个与 iPhone 交互的 Web 应用程序。 iPhone iphone实际上会以plist的形式向服务器发送信息。因此,看到类似的情况并不少见......

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

现在我知道这些数据以某种方式进行了散列/加密。当我使用编辑器(属性列表编辑器)打开 plist 时,它向我显示了一种更“人类可读”的格式。例如,上面的数据将被转换成类似的东西......

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

知道转换它的方法是什么吗?主要是我希望将其转换为 Java 字符串。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2024-10-01 21:14:05

根据我们 wikipedia 的朋友的说法, 标签包含 Base64 编码 数据。因此,使用您最喜欢的 Java“Base64”类进行解码(另请参阅此问题) 。

附:从技术上讲,这既不是“散列”也不是“加密”,只是“编码”。 “散列”意味着一种单向转换,其中多个输入值可以产生相同的输出值。 “加密”意味着需要(通常是秘密的)“密钥”来反转加密。 Base64 编码只是一种仅使用可打印字符来表示任意二进制数据的方法。

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.

逐鹿 2024-10-01 21:14:05

Base64 解码后,您需要对其进行十六进制编码。这就是 PL Editor 向您展示的内容。

所以...

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

可以表示为...

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

以获得...

<516df5aa 3c5b5259 74ecf683 4401259f 711630ba 236c59ac 9bb2ee44 0b1c8ab2>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文