Beispiel #1
0
    def test_aes(self):
        bt = Braintree(public_key)
        key, payload = bt._aes_encrypt('hello world')

        iv = payload[:Braintree.IV_LENGTH]
        encrypted_data = payload[Braintree.IV_LENGTH:]

        aes = AES.new(key, AES.MODE_CBC, iv)
        decrypted_data = aes.decrypt(encrypted_data)
        decrypted_data = unpad(decrypted_data)
        self.assertEqual(decrypted_data, 'hello world')
Beispiel #2
0
    def test_aes(self):
        bt = Braintree(public_key)
        key, payload = bt._aes_encrypt('hello world')

        iv = payload[:Braintree.IV_LENGTH]
        encrypted_data = payload[Braintree.IV_LENGTH:]

        aes = AES.new(key, AES.MODE_CBC, iv)
        decrypted_data = aes.decrypt(encrypted_data)
        decrypted_data = unpad(decrypted_data)
        self.assertEqual(decrypted_data, 'hello world')
Beispiel #3
0
    def test_full(self):
        bt = Braintree(public_key)
        full_message = bt.encrypt('hello world')

        _, prefix, encrypted_key, encrypted_payload = full_message.split('$')
        self.assertEqual(_ + '$' + prefix, Braintree.PREFIX)

        # strip rsa
        encrypted_payload = encrypted_payload.decode('base64')
        decrypted_key = self._decrypt_rsa(encrypted_key.decode('base64')).decode('base64')

        # strip aes
        iv = encrypted_payload[:Braintree.IV_LENGTH]
        encrypted_data = encrypted_payload[Braintree.IV_LENGTH:]

        aes = AES.new(decrypted_key, AES.MODE_CBC, iv)
        decrypted_data = aes.decrypt(encrypted_data)
        decrypted_data = unpad(decrypted_data)

        self.assertEqual(decrypted_data, 'hello world')
Beispiel #4
0
    def test_full(self):
        bt = Braintree(public_key)
        full_message = bt.encrypt('hello world')

        _, prefix, encrypted_key, encrypted_payload = full_message.split('$')
        self.assertEqual(_ + '$' + prefix, Braintree.PREFIX)

        # strip rsa
        encrypted_payload = encrypted_payload.decode('base64')
        decrypted_key = self._decrypt_rsa(
            encrypted_key.decode('base64')).decode('base64')

        # strip aes
        iv = encrypted_payload[:Braintree.IV_LENGTH]
        encrypted_data = encrypted_payload[Braintree.IV_LENGTH:]

        aes = AES.new(decrypted_key, AES.MODE_CBC, iv)
        decrypted_data = aes.decrypt(encrypted_data)
        decrypted_data = unpad(decrypted_data)

        self.assertEqual(decrypted_data, 'hello world')