msg = string + rsa_encryped_result rsa_encrypt(msg) failed to decrypt when we connect string with rsaResult include code
we tried to change to base64 instead of String, also use PAD ,
class Crypto():
def __init__(self):
random_generator = Random.new().read
self.private_key = RSA.generate(1024, random_generator)
self.public_key = self.private_key.publickey()
def get_string_public_key(self):
return self.public_key.exportKey()
def decrypt_message(self, message):
decrypted_message = self.private_key.decrypt(message)
return decrypted_message
def encrypt_message(message, public_key):
encrypted_message = public_key.encrypt(message, 32)[0]
return encrypted_message
def make_public_key(string_key):
return RSA.importKey(string_key)
bob = Crypto()
first_msg = "Hello World"
print first_msg + ' - the original'
msg1 = encrypt_message(first_msg, make_public_key(bob.get_string_public_key()))
msg2 = msg1 + "Hello again"
msg3 = encrypt_message(msg2, make_public_key(bob.get_string_public_key()))
# work ok
print 'simple one \r\n', bob.decrypt_message(msg1)
print msg2 + ' the second one'
msg3 = bob.decrypt_message(msg2)
# does not work
print 'second one \r\n', msg3
print msg3.find("again")
we expected to find the string 'again' inside msg3 but we didnt
second one
w%z�� ����bV�W�T ?�q
H?�)�9��)0�Ӕk��Ӯ4dK-�CH��!�b�5��d�_������Ð�a2g
����K��_E�n�Wܧlz]y�~�jBY�̐&}\��h���$��WZ��
-1