I have been using RSA Public/Private Key Pair to encrpyt data:
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
publickey = key.publickey()
and write it to a file. The probelm I am getting is when I read any file in bytes:
f = open('test','rb')
d = f.read()
enc_data = publickey.encrypt(d,32)
I am getting the encrypted data as a tuple
>>> type(enc_data)
>>> <class 'tuple'>
The problem is when I try to write the encrypted text in any newly created file I am not able to do it in any mode
o = open('out','wb') #same with 'w' mode
o.write(enc_data)
It displays the error:
Traceback (most recent call last):
File "<pyshell#103>", line 1, in <module>
o.write(enc_data)
TypeError: must be str, not tuple
How to get my encrypted data saved?