how to import RSA Algorithm python code example
Example 1: python rsa
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
publickey = key.publickey
encrypted = publickey.encrypt('encrypt this message', 32)
print 'encrypted message:', encrypted
f = open ('encryption.txt', 'w'w)
f.write(str(encrypted))
f.close()
f = open ('encryption.txt', 'r')
message = f.read()
decrypted = key.decrypt(message)
print 'decrypted', decrypted
f = open ('encryption.txt', 'w')
f.write(str(message))
f.write(str(decrypted))
f.close()
Example 2: python rsa encryption and decryption with password
python rsa encryption and decryption with password