How do I encrypt large amounts of data using asymmetric cryptography?

On the client side of my application, I want to encrypt text (which can be of any size) using the public key. After that I will send this packet to the server. On the server side, I want to decrypt this packet using my private key.

I cannot use RSA because the packet size can be any size, even larger than the key. I can do this with OpenSSL by creating files and stuff with Encrypt / Decrypt files.

The question is, is there any other way of programming?

+3


source to share


2 answers


You need to implement a hybrid encryption scheme . One example of such a scheme is OpenPGP.

In a hybrid encryption scheme, a symmetric session key is generated that is used for only 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 with the sender's private key. Finally, the whole package is packed together and sent to the door.



I would recommend that you use something like BouncyCastle for Java OpenPGP encryption. There is no need to reinvent the wheel.

+1


source


Use PKCS # 7 / CMS or OpenPGP depending on whether you prefer to deal with X.509 certificates (they can be self-signed) or PGP keys. Both technologies provide a comparable level of security and differences (in the case of your task) mainly in the key format.



BouncyCastle or our SecureBlackbox are widely used libraries suitable for both.

+1


source







All Articles