Android——加密与解密
我正在通过 HTTP 连接下载 XML 文件,现在我需要在 FTP 中加密 XML,在下载之前我将检查 XML 签名(或解密),然后再使用它。我已经获得了应用程序签名(976 个字母和数字的组合),但我不知道是否可以使用我的签名字符串来验证我的 XML?或者私钥/公钥解决方案?但是如何创建密钥以及如何将它们存储在 APK 中?
谢谢
I am downloading XML file via HTTP connection and now I need to have encrypted XML in my FTP and befaore download I will check XML signature (or decrypt it) before any other use of it. I have got my app signature (combination of 976 letters and numbers) and I don't know, can I use my signature string to verify my XML? Or private/public key solution? But how to create keys and how to store them in APK?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的方法是使用非对称密钥对(RSA 最常见),您可以在 FTP 站点上对数据进行签名,并将您的私钥,呃,私钥和公钥保存在 Android 设备上。您可以使用另一个密钥对进行加密/解密。您可以使用您的签名字符串作为 Android 设备上的私有解密密钥的密码。确保您的应用程序不易受到 padding oracle 攻击(加密,然后签名,或者如果解密失败则不通知另一方)。
请注意,实现您自己版本的 XML 签名/验证或 XML 加密/解密可能非常困难(并且充满了至少与使用 XML 安全相关库相匹配的陷阱)。我建议尝试将 XML 包装在 CMS 容器中。
对于其他用户,您的后一个问题的链接:
Android - 验证 XML 的签名
The best way is to use a asymmetric key pair (RSA is most common) where you sign the data on the FTP site, keeping your private key, uh, private and the public key on the android device. You may use another key pair for encryption/decryption. You could use your signature string as a password to your private decryption key on the android device. Make sure your application is not vulnerable to padding oracle attacks (encrypt, then sign or don't notify the other side if decryption failed).
Note that implementing your own version of the XML sign/verify or XML encrypt/decrypt may be very hard to do (and fraught with pitfalls that at least match using XML security related libraries). I would recommend trying for wrapping your XML within a CMS container instead.
For other users, a link to the later question of yours:
Android - verify the signature of XML
owlstead 是对的,尝试重新发明轮子并不是最佳选择。另一方面,如果您确实想要实现它或了解如何实现它,那么签名和验证 XML 文件的内部结构就很简单。首先,生成 RSA 公钥/私钥对。然后,您获取 XML 文件的哈希值并使用 RSA 密钥加密该哈希值,并将加密数据与 XMl 文件一起发送,这样您的 XML 文件就已签名。要验证文件,您只需获取 XML 文件的哈希值并将其与加密哈希值(解密后)进行比较,看看它们是否匹配。如果是这样,则说明文件在此过程中没有经过调整。
owlstead is right, trying to reinvent the wheel is not the optimal choice. On the other hand, the internals of signing and verifying XML files are trivial if you really want to implement it, or learn how to do it. First, you generate a RSA public/private key pair. Then you take the hash of the XML file and encrypt the hash with your RSA key and ship the encrypted data along with the XMl file, which now makes your XML file signed. To verify the file, you simply take the hash of the XML file and compare it with the encrypted hash (after decrypting it) to see if they match. If so, file was not tempered with along the way.