Campbell Ritchie wrote:Welcome to the Ranch
![]()
I have added some new lines to your code because long lines are difficult to read. I shall move this discussion because it is too difficult for "beginning".
James Sabre wrote:One can RSA encrypt the whole file by breaking the file into sections shorter than the RSA modulus (-11 bytes if one uses PKCS1 padding) but this is very very very slow. The standard approach to RSA encryption of files of any length is to use a hybrid approach. One uses a symmetric encryption (AES, Blowfish , DES etc) to actually encrypt the data using a random 'session' key and one only uses RSA to encrypt the session key. The encrypted file then consists of the concatenation of the encrypted session key and the symmetric encrypted file content. To decrypt one just extracts the encrypted session key, RSA decrypts it then using the symmetric algorithm decrypts the file content using this session key.
There is a good description of the approach in section 13.6 of "Practical Cryptography" by Ferguson and Schneier. PGP uses this general approach but the detail differs from that described in section 13.6 .