Ejemplo n.º 1
0
    def test_get_decrypted_message(self):
        recipient_key_bytes = int(self.recipient_key.publickey().n.bit_length() / 8)
        decryption = Decryption(self.recipient_key, self.sender_key)
        iv = Random.new().read(16)
        key = Random.new().read(32)
        encrypted_key = Random.new().read(recipient_key_bytes)
        message = "a" * 2000
        block_size = AES.block_size
        pad = lambda s: s + (block_size - len(s) % block_size) * chr(block_size - len(s) % block_size)
        message_to_encrypt = pad(message)
        cipher = AES.new(key, mode=AES.MODE_CBC, IV=iv)
        encrypted_message = cipher.encrypt(message_to_encrypt)

        self.assertEqual(message,
                         decryption.get_decrypted_message(iv, key, iv + encrypted_key + encrypted_message))
Ejemplo n.º 2
0
    def test_get_decrypted_message(self):
        recipient_key_bytes = int(
            self.recipient_key.publickey().n.bit_length() / 8)
        decryption = Decryption(self.recipient_key, self.sender_key)
        iv = Random.new().read(16)
        key = Random.new().read(32)
        encrypted_key = Random.new().read(recipient_key_bytes)
        message = ("a" * 2000).encode('utf-8')
        block_size = AES.block_size
        pad = lambda s: s + (block_size - len(s) % block_size) * chr(
            block_size - len(s) % block_size).encode('utf-8')
        message_to_encrypt = pad(message)
        cipher = AES.new(key, mode=AES.MODE_CBC, IV=iv)
        encrypted_message = cipher.encrypt(message_to_encrypt)

        self.assertEqual(
            message,
            decryption.get_decrypted_message(
                iv, key, iv + encrypted_key + encrypted_message))