Python rsa key decrypt string

broken image
broken image
broken image

# use base64 for save encrypted_message in database without problems with encoding Public_key_object = RSA.importKey(public_key)Įncrypted_message = public_key_object.encrypt(self._to_format_for_encrypt(message), random_phrase) Print 'encrypted message:', encrypted #ciphertextį.write(str(encrypted)) #write ciphertext to fileĬlass PublicKeyFileExists(Exception): pass #message to encrypt is in the above line 'encrypt this message' Publickey = key.publickey # pub key export for exchangeĮncrypted = publickey.encrypt('encrypt this message', 32) Key = RSA.generate(1024, random_generator) #generate public and private keys It seems like it is not reading the ciphertext from the file.Ĭan anyone help me write this code so decryption reads ciphertext from file and then uses key to decrypt ciphertext? import Crypto As you can see in my code below, when I put in decrypted = key.decrypt(message) that the program works, yet the decrypted message is encrypted again. I am having trouble with the decryption portion. Then I am reading ciphertext from file and decrypting text using key. I am creating a private/public key pair, encrypting a message with keys and writing message to a file. I need help using RSA encryption and decryption in Python.

broken image