RSA加密数据可以通过HTTP发送吗?
我的应用程序使用 RSA 加密数据,然后通过 HTTP 发送到远程服务器。当然数据是byte[]形式的。能否安全地转换为字符串、进行 url 编码并在 URL 的查询中发送?还是需要编码?
My application encrypts data with RSA to be sent to a remote server over HTTP. Of course the data is in byte[] form. Can it safely be converted to a string, url encoded, and sent in the query of the URL? Or does it need to be encoded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的当然。这里没有任何特定于 RSA 的内容;您只是上传二进制数据。
您可以POST任意长度的数据;您可以将其作为原始二进制文件发布,假设另一端可以处理它 - 即您可以绕过框架中尝试将其解析为参数变量的部分 - 或者再次作为 URL 编码/base-64-encoded-URL-encoded。< /p>
您可以将其打包为文件上传(多部分/表单数据)并发布。同样是任何长度的数据,并且这将仅进行 Base64 编码,因此可能会更短一些。它也将更容易集成到您的服务器应用程序框架中,因为它可能内置文件上传支持。
Yes, of course. There's nothing RSA-specific here; you're just uploading binary data.
Sent in a GET query string: yes, you can URL encode it (or base64-encode it then URL encode it) provided it isn't too long - some clients and servers have URL length limits.
You can POST any length of data; you can POST as raw binary assuming the other end can handle it - i.e. you can bypass the parts of your framework that will attempt to parse it into parameter variables - or again as URL encoded / base-64-encoded-URL-encoded.
You can wrap it up as a file upload (multipart/form-data) and POST that. Again any length of data, and this will be base64 encoded only so might work out a bit shorter. It will also be easier to integrate into your server app framework as it'll likely have file upload support built-in.
为了安全起见,您应该将其编码为 Base64。您可以使用 Apache Commons Codec 项目中的 Base64 类。
You should encode it to Base64 to be on the safe side. You could use the Base64 class from the Apache Commons Codec project.
对于 PHP,请使用 rawurlencode(),否则 $_GET 数据将不会始终被正确编码...有关 rawurlencode() 和 urlencode() 之间的区别,请参阅手册。
With PHP use rawurlencode() otherwise the $_GET data will not always be correctly encoded... See the manual for the difference between rawurlencode() and urlencode().