Currently I can encrypt using a variable in the same file as a message such as line 10. However I need help on how to add the b"" at line 21 since i am reading in from a file.
from base64 import b64encode
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Random import get_random_bytes
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import glob
for item in glob.glob("*.txt"):
  #context = b"Secret Message"
  k = get_random_bytes(16)
  pk = RSA.import_key(open("publicKey.pem").read())
  file_out = open("CK.bin", "wb")
  cipher_rsa = PKCS1_OAEP.new(pk)
  CK = cipher_rsa.encrypt(k)
  file_out.write(CK)
  file_out.close()
  fileTxtIn = open(item, 'r')
  context = fileTxtIn.readlines()
  cipher = AES.new(k, AES.MODE_CBC)
  CM_bytes = cipher.encrypt(pad(context, AES.block_size))
  iv = cipher.iv
  iv_out = open("iv_file", "wb")
  iv_out.write(iv)
  CM_out = open("CM_file.enc", "wb")
  CM_out.write(CM_bytes)
  fileTxtIn.close()
Much appreicated if you can help me here, thanks.
 
    