1
votes

I'm writing a python script to encrypt/decrypt strings with RSA. I have no problems with the algorithm itself, but I don't understand how to use it correctly.

I mean, there is no point in encrypting every each symbol in a string separately. Because same symbols will give us same ciphers (like Caesar cipher). So I think I should divide the whole message into blocks of same length. But it makes it difficult to decrypt the message. Because after you encrypt the blocks, the length of each block could change. So when decrypting, you don't know where a certaing blocks starts and where it ends. For example, when I encrypt "stronger" with RSA I get:

5716225862

I divided the original message into 4 blocks of 4 symbols. But after encrypting I get a message of 10 symbols. And that's the problem. Hope, you understand what I mean. Sorry for my bad English.

1
For a start spend a whole day (8 hours) studying encryption, there is substantial information the Internet. That will give you a good starting point. Securely using encryption is not easy.zaph
Spend one of those hours studying PKCS#1, particularly section 4President James K. Polk

1 Answers

3
votes

Simply said, RSA is not for directly encrypting plain text, it is used for encrypting a symmetric key (AES, for instance), and this is with this symmetric key that you will encrypt (and further decrypt) your plain text.

Since the plain text may have any size, it is encrypted using AES with a stream cipher (for instance AES-256-GCM) or a block cipher (for instance AES-256-CBC).

With AES, same symbols will not give same ciphers, since you have to choose a new random IV (initialization vector) each time you encrypt your plain text.

So, you need to use a 2-steps encryption scheme: use RSA to encrypt a symmetric key, and use this symmetric key to encrypt your plain text.