简体   繁体   English

如何使用非对称加密技术加密大量数据?

[英]How to encrypt large amounts of data using asymmetric cryptography?

In the client side of my application I want to encrypt text (that could be of any size) using a public key. 在我的应用程序的客户端,我想使用公钥加密文本(可以是任何大小)。 After that I'll send this packet to a server. 之后我会将此数据包发送到服务器。 In the server side I want to decrypt this packet using my private key. 在服务器端,我想使用我的私钥解密此数据包。

I can't use RSA, because the packet size could be of any size, even bigger then the key. 我不能使用RSA,因为数据包大小可以是任何大小,甚至比密钥大。 I can do that using OpenSSL, creating files and stuff with the results of Encrypt/Decrypt. 我可以使用OpenSSL,使用Encrypt / Decrypt的结果创建文件和内容。

The question is: is there another way to programmatic do that? 问题是:是否还有另一种方法可以做到这一点?

You need to implement a hybrid encryption scheme . 您需要实施混合加密方案 One example of such a scheme is OpenPGP. 这种方案的一个例子是OpenPGP。

In a hybrid encryption scheme, one generates a symmetric session key that is used just for one message. 在混合加密方案中,可以生成仅用于一条消息的对称会话密钥。 The symmetric key encrypts the payload, while the public key of the recipient(s) is used to encrypt the symmetric key. 对称密钥加密有效载荷,而接收者的公钥用于加密对称密钥。 The payload is often signed by the private key of the sender. 有效负载通常由发送方的私钥签名。 Finally, the whole lot is packaged together and sent out the door. 最后,整个地块被打包在一起并送出了门。

I would recommend you use something like BouncyCastle to do OpenPGP encryption in Java. 我建议你使用类似BouncyCastle的东西在Java中进行OpenPGP加密。 No need to reinvent the wheel. 无需重新发明轮子。

Use either PKCS#7/CMS or OpenPGP depending on whether you prefer to deal with X.509 certificates (they can be self-signed) or PGP keys. 使用PKCS#7 / CMS或OpenPGP取决于您是否更愿意处理X.509证书(它们可以是自签名的)或PGP密钥。 Both technologies provide comparable level of security and the differences (in case of your task) are mainly in the key format. 这两种技术都提供相当级别的安全性,差异(在您的任务的情况下)主要是密钥格式。

BouncyCastle or our SecureBlackbox are the widely used libraries suitable for both variants. BouncyCastle或我们的SecureBlackbox是广泛使用的适用于这两种变体的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM