Commit 5cbc764b authored by Tijmen de Mes's avatar Tijmen de Mes

Refactored encrypt message

parent 5d99a16f
...@@ -151,17 +151,14 @@ class MessageStream(object, metaclass=MediaStreamType): ...@@ -151,17 +151,14 @@ class MessageStream(object, metaclass=MediaStreamType):
def enable_pgp(self): def enable_pgp(self):
self._load_pgp_keys() self._load_pgp_keys()
def encrypt(self, content): def encrypt(self, content, content_type=None):
session = self.blink_session
# print('-- Encrypting message') # print('-- Encrypting message')
stream = session.fake_streams.get('messages')
pgp_message = PGPMessage.new(content, compression=CompressionAlgorithm.Uncompressed) pgp_message = PGPMessage.new(content, compression=CompressionAlgorithm.Uncompressed)
cipher = SymmetricKeyAlgorithm.AES256 cipher = SymmetricKeyAlgorithm.AES256
sessionkey = cipher.gen_key() sessionkey = cipher.gen_key()
encrypted_content = stream.public_key.encrypt(pgp_message, cipher=cipher, sessionkey=sessionkey) encrypted_content = self.public_key.encrypt(pgp_message, cipher=cipher, sessionkey=sessionkey)
encrypted_content = stream.remote_public_key.encrypt(encrypted_content, cipher=cipher, sessionkey=sessionkey) encrypted_content = self.remote_public_key.encrypt(encrypted_content, cipher=cipher, sessionkey=sessionkey)
del sessionkey del sessionkey
return str(encrypted_content) return str(encrypted_content)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment