用 ANSI C 加密,用 Java 解密
我必须通过套接字从 ANSI C 应用程序向 Java 应用程序发送一个短字符串 - 已经完成。因为它的重要数据我必须使用“abc123”之类的密码对其进行加密。我应该如何以最简单的方式做到这一点?
I have to send a short string from ANSI C application to Java application through a socket - already done. Because its important data I have to encrypt it using password like "abc123". How should I do it in the simpliest way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为“套接字”指的是 TCP/IP 连接。在这种情况下,您应该考虑使用安全套接字层 (SSL)。 SSL 几乎解决了与通过线路发送数据相关的大部分安全问题。您唯一需要解决的是如何将密钥分发到管道的每一端。
我强烈建议您不要推出自己的系统。加密很难正确,因此请使用现有的、经过良好测试的实现。
如果您谈论的是 Unix 域套接字,那么您可能不需要费心加密,因为域套接字只是进程间管道。
By "socket" I assume you mean a TCP/IP connection. In that case you should consider using Secure Sockets Layer (SSL). SSL pretty much solves most of the security problems associated with sending data across the wire. The only thing you need to work out is how to distribute keys to each end of the pipe.
I strongly recommend that you don't roll your own system. Crypto is hard to get right so use an existing, well tested implementation.
If you're talking about a Unix domain socket then you probably don't need to bother with encryption since domain sockets are just inter-process pipes.
如前所述,这在很大程度上取决于您希望其安全程度,明智的答案是找到同一密码系统的 Java 和 C 实现并使用它们。
如果您愿意接受家庭酿造通常带来的较低安全性,我假设您在问题中采用“最简单的方式”,并假设两端的源和运行时都是安全的。 IE你只需要担心传输中的数据被拦截。您可以使用您想要的任何密码作为伪随机数生成器的种子(大素数除以字节索引或类似的余数),并将数据字节与生成的随机数进行异或。不是最安全的,但实施起来会非常快。
As mentioned it depends very much on how secure you want this to be, the sensible answer is to find a Java and C implementation of the same cryptosystem and use those.
If you are willing to accept the lower security that usually comes with home brewing these things which I assume you are by the "simplest way" in your question and assuming both the source and runtime for both ends are secure. I.E. you only need to worry about the data in transit being intercepted. You could just use whatever password you desire as a seed for a pseudo random number generator (remainder of dividing a large prime by the byte index or similar) and XOR the bytes of data with the random numbers generated. Not the most secure but would be very quick to implement.