


Your question addresses the block cipher concept. How to Strengthen the Security of RSA-OAEP, Boldyreva et al. There are modifications of the RSA algorithm, which are considered suitable for long messages, after analyzing known games and attacks. Symmetric ciphers such as AES directly operate on binary data, so besides handling of the IV and padding, the data can be encrypted directly without conversion. RSA in a secure mode of operation has a certain overhead and a maximum per operation, so generally a symmetric key is encrypted or derived using RSA instead this symmetric key is then used to encrypt the data. Instead we use a protocol such as PGP which performs hybrid encryption. The main other reason is that RSA encryption and especially decryption operations are very inefficient compared to e.g. This is one reason why files are generally not encrypted using RSA directly. Adding the padding means a not-insignificant amount of overhead is added before the message is applied the amount of plaintext is much smaller than the RSA modulus. This would be either the PKCS#1 v1.5 defined padding or OAEP padding. In PKCS#1 based RSA OS2IP is not used directly though: first a security relevant padding is applied. If the bytes are already in the right form then it is just a question of interpreting the bytes as a number, as the computer always handles everything as binary anyway. An octet string is nothing more than a byte array. OS2IP means octet string to integer primitive.

In your case the text is obviously already encoded as bytes files consist of bytes after all, and you are opening the file as a binary file (the b in the rb flag). encode the bytes to integer - this is part of the encryption operation in RSA as specified in PKCS#1, and is performed using a function called OS2IP.encode the text to bytes - this generally requires a character encoding such as UTF-8 or Latin encoding.
