I am trying to write a RSA encryption software tool that will use the same key every single time. here is what I have so far.
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
key = <_RSAobj @0x24b6348 n<1024>,e,d,p,q,u,private>
publickey = key.publickey()
encrypted = publickey.encrypt('hi', 32)
print(encrypted)
I get a syntax error at line 5 pointing at the < sign. I know that this is a valid private key. what is the problem and how do I fix it. Also I am using python 2.7.3
[EDIT] I get the key from this code
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
import os
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
print(key)
raw_input()
Also I am getting a 'RSA key format not supported error' from this code after the 'raw_input()'
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
text_file = open("keyfile.txt", "w")
text_file.write('<_RSAobj @0x24b6348 n<1024>,e,d,p,q,u,private>')
text_file.close()
raw_input()
with open('keyfile.txt', 'r') as f:
externKey = f.readline()
key = RSA.importKey(externKey, passphrase=None)
publickey = key.publickey()
encrypted = publickey.encrypt('hi', 32)
print(encrypted)
RSA.importKey("key string here")