Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking up large data for RSA encryption

Recently we've been diving into using OpenSSL to help encrypt/decrypt some data we have. Each "client" will have Public/Private key pair and X509 Certificate given to them by a local Certificate Authority. I'm now looking into encrypting/decrypting data with that key pair.

Everything I've looked into show using the methods RSA_public_encrypt and RSA_private_decrypt for RSA encryption. But the amount of data I can encrypt at once is limited by RSA_size(rsa) - 41 for the padding type RSA_PKCS1_OAEP_PADDING. So my question is how to encrypt larger amounts of data while sticking to our RSA scheme (no static keyphrases, etc). I was thinking about breaking the data up into chunks and then encrypting it but that seems like it's defeating the point of padding.

Any help would be appreciated.

like image 701
Staros Avatar asked Mar 11 '11 19:03

Staros


1 Answers

Even if you break the data, you will find out, that the speed is prohibitively slow. The right method is

  1. Generate random key for symmetric algorithm
  2. encrypt the data using symmetric algorithm and the random key
  3. encrypt the random key using your public key and store it in the encrypted form next (or before) the data.
like image 187
Eugene Mayevski 'Callback Avatar answered Sep 25 '22 02:09

Eugene Mayevski 'Callback