与结果有差异吗?
我使用了一个小片段来使用 AES128 编码和解码字符串。问题是,当我在不同平台上编码和解码时,似乎存在差异。如果我在 android SDK 或计算机上运行相同的代码,即使我使用相同的种子/哈希,我似乎也会得到不同的结果。
需要澄清的是,执行结果(加密值)因平台而异。在 android 中,我得到另一个值,在标准 java 应用程序中,我得到另一个值。
可能出了什么问题?
I have used a small snippet to encode, and decode a string using AES128. The issue is that it appears, that there are differences when I encode and decode on different platforms. If I run the same code on the android SDK or on the computer, I seem to get different results, even if I use the same seed/hash.
To clarify, the execution result (the encrypted value) differs from one platform to the other. In android, I get another value, and in a standard java application, I get another one.
What could possibly be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到Stackoverflow,首先只是一个整理点,最好不要使用这里的“回答”选项来回复评论,只需点击“添加评论”即可。
查看此链接以获取加密示例使用 DES 加密字符串
请注意 getBytes 用“UTF8”限定的方式。然后对其进行 Base64 编码。一些更高级别的 Android(API 及更高版本)内置了 base64,否则很容易编写自己的,或者只是 Google for Java + bas64 + 示例。如果您使用此示例代码,它应该在两个平台上给出相同的结果。
Welcome to Stackoverflow, first just a housekeeping point, it's best not to use the 'answer' option here for replying to comments, just click 'add comment'.
Have a look at this link for an example of encryption Encrypting a String with DES
Note the way the getBytes is qualified with "UTF8". It's then base64 encoded. Some higher levels of Android (API and onwards) have the base64 built in, otherwise it's easy enough to write your own, or just Google for Java + bas64 + example. If you use this sample code it should give you the same result on both platforms.